browse.js 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,8 @@
1
+ # Browse.js
2
+ ## A lightweight yet versatile file browser written in vanilla JavaScript.
3
+
4
+ Open `demo/index.html` in a browser (for example, using `python -m http.server 8000`) to run a demo.
5
+
6
+ ![Browse.js Screenshot](./demo/screenshot-simple.png)
7
+
8
+ © 2026 Daniel Foerster. All rights reserved. Made available under the Apache 2.0 license; see [LICENSE](./LICENSE) for details.
@@ -0,0 +1,137 @@
1
+ /**
2
+ * @typedef {Object} IconRule
3
+ * @property {string} icon - The icon URL
4
+ * @property {function(string):boolean} [typeMatch] - Optional function to match against the MIME type of a file
5
+ * @property {string[]} [exts] - Optional array of file extensions (with dot) to match against the file name
6
+ */
7
+ /**
8
+ * @typedef {Object} FileItem
9
+ * @property {string} name - The display name of the file or folder
10
+ * @property {string} [thumbnail] - Optional data URL for the thumbnail image
11
+ * @property {Object} [meta] - Optional metadata object with additional info (e.g. size, type)
12
+ * @property {FileItem[]} [children] - If present, indicates this item is a folder containing these child items
13
+ */
14
+ /**
15
+ * @typedef {Object} BrowseJSOptions
16
+ * @property {string} [rootName] - The display name for the root folder (default: "Root")
17
+ * @property {function(FileItem, number):void} [onSelect] - Callback when a file is selected, receives the file item and its index
18
+ * @property {string} [detailsText] - Default text to show in the details pane when no selection is made (default: "Select a file")
19
+ * @property {Object} [icons] - Custom icons configuration
20
+ * @property {IconRule[]} [icons.rules] - Custom rules for determining icons based on MIME type or file extension
21
+ * @property {string} [icons.folder] - Custom icon URL for folders
22
+ * @property {string} [icons.default] - Custom icon URL for files that don't match any rule
23
+ * @property {boolean} [multiSelect] - If true, allows selecting multiple files (default: false)
24
+ * @property {function(string):?(FileItem)} [onCreateFolder] - Optional callback invoked when creating a new folder. If it returns a FileItem, it will be added to the current folder.
25
+ * @property {function(File[]):?(FileItem|FileItem[])} [onUpload] - Optional callback invoked when files are uploaded. If it returns FileItem(s), they'll be added to the current folder.
26
+ */
27
+ export class BrowseJS {
28
+ /**
29
+ * @param {string|Element} container - The the container element to render the gallery into. Can be a DOM element, ID, or selector string.
30
+ * @param {FileItem[]} files - An array of file items to display in the root folder
31
+ * @param {BrowseJSOptions} opts - Configuration options (see BrowseJSOptions typedef for details)
32
+ */
33
+ constructor(container: string | Element, files?: FileItem[], opts?: BrowseJSOptions);
34
+ container: Element;
35
+ opts: BrowseJSOptions;
36
+ iconRules: {
37
+ icon: string;
38
+ typeMatch: (t: any) => any;
39
+ exts: string[];
40
+ }[] | IconRule[];
41
+ folderIcon: string;
42
+ defaultIcon: string;
43
+ multi: boolean;
44
+ selectedIndices: any;
45
+ stack: {
46
+ name: string;
47
+ files: FileItem[];
48
+ }[];
49
+ breadcrumbEl: HTMLElement;
50
+ crumbsWrap: HTMLDivElement;
51
+ controlsEl: HTMLDivElement;
52
+ detailsEl: HTMLElement;
53
+ galleryEl: HTMLDivElement;
54
+ _fileInput: HTMLInputElement;
55
+ getIconForItem(item: any): string;
56
+ render(): void;
57
+ updateSelectionUI(): void;
58
+ renderDetails(): void;
59
+ renderBreadcrumb(): void;
60
+ currentFolder(): string;
61
+ currentFiles(): FileItem[];
62
+ addFiles(files: any): void;
63
+ getSelectedPaths(): any[];
64
+ handleCreateFolder(): Promise<void>;
65
+ _creatingFolder: boolean;
66
+ handleUpload(): Promise<void>;
67
+ handleDropFiles(files: any): Promise<void>;
68
+ select(i: any): void;
69
+ enterFolder(i: any): void;
70
+ goToCrumb(idx: any): void;
71
+ }
72
+ export type IconRule = {
73
+ /**
74
+ * - The icon URL
75
+ */
76
+ icon: string;
77
+ /**
78
+ * - Optional function to match against the MIME type of a file
79
+ */
80
+ typeMatch?: (arg0: string) => boolean;
81
+ /**
82
+ * - Optional array of file extensions (with dot) to match against the file name
83
+ */
84
+ exts?: string[];
85
+ };
86
+ export type FileItem = {
87
+ /**
88
+ * - The display name of the file or folder
89
+ */
90
+ name: string;
91
+ /**
92
+ * - Optional data URL for the thumbnail image
93
+ */
94
+ thumbnail?: string;
95
+ /**
96
+ * - Optional metadata object with additional info (e.g. size, type)
97
+ */
98
+ meta?: any;
99
+ /**
100
+ * - If present, indicates this item is a folder containing these child items
101
+ */
102
+ children?: FileItem[];
103
+ };
104
+ export type BrowseJSOptions = {
105
+ /**
106
+ * - The display name for the root folder (default: "Root")
107
+ */
108
+ rootName?: string;
109
+ /**
110
+ * - Callback when a file is selected, receives the file item and its index
111
+ */
112
+ onSelect?: (arg0: FileItem, arg1: number) => void;
113
+ /**
114
+ * - Default text to show in the details pane when no selection is made (default: "Select a file")
115
+ */
116
+ detailsText?: string;
117
+ /**
118
+ * - Custom icons configuration
119
+ */
120
+ icons?: {
121
+ rules?: IconRule[];
122
+ folder?: string;
123
+ default?: string;
124
+ };
125
+ /**
126
+ * - If true, allows selecting multiple files (default: false)
127
+ */
128
+ multiSelect?: boolean;
129
+ /**
130
+ * - Optional callback invoked when creating a new folder. If it returns a FileItem, it will be added to the current folder.
131
+ */
132
+ onCreateFolder?: (arg0: string) => (FileItem) | null;
133
+ /**
134
+ * - Optional callback invoked when files are uploaded. If it returns FileItem(s), they'll be added to the current folder.
135
+ */
136
+ onUpload?: (arg0: File[]) => (FileItem | FileItem[]) | null;
137
+ };
package/dist/browse.js ADDED
@@ -0,0 +1 @@
1
+ function svgDataUrlFromSvg(svg){return"data:image/svg+xml;utf8,"+encodeURIComponent(svg)}function escapeText(t){return String(t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function svgDocumentIcon(label,bg="#e9eefc",w=240,h=310){const safe=escapeText(label||"");const fold=84;const bodyPath=`M0 0 H${w-fold} L${w} ${fold} V${h} H0 Z`;const foldPath=`M${w-fold} 0 v${fold} h${fold} Z`;const svg=`<?xml version='1.0' encoding='utf-8'?><svg xmlns='http://www.w3.org/2000/svg' width='${w}' height='${h}' viewBox='0 0 ${w} ${h}'>`+`<path d='${bodyPath}' fill='${bg}' stroke='#0b12200a' stroke-linejoin='round'/>`+`<path d='${foldPath}' fill='#0000001a' stroke='#0b122005'/>`+`<text x='50%' y='58%' dominant-baseline='middle' text-anchor='middle' font-family='Inter,Arial,Helvetica,sans-serif' font-size='36' fill='#0b1220'>${safe}</text>`+`</svg>`;return svgDataUrlFromSvg(svg)}function svgFolderIcon(label,bg="#ffd7a8",w=420,h=320){const safe=escapeText(label||"");const tabH=44;const tabW=120;const svg=`<?xml version='1.0' encoding='utf-8'?><svg xmlns='http://www.w3.org/2000/svg' width='${w}' height='${h}' viewBox='0 0 ${w} ${h}'>`+`<rect x='6' y='34' rx='12' ry='12' width='${w-12}' height='${h-40}' fill='${bg}' stroke='#0b12200a'/>`+`<rect x='18' y='12' rx='8' ry='8' width='${tabW}' height='${tabH}' fill='${bg}'/>`+`<text x='50%' y='62%' dominant-baseline='middle' text-anchor='middle' font-family='Inter,Arial,Helvetica,sans-serif' font-size='36' fill='#0b1220'>${safe}</text>`+`</svg>`;return svgDataUrlFromSvg(svg)}const DEFAULT_ICON_RULES=[{icon:svgDocumentIcon("IMG","#c7ddff"),typeMatch:t=>t.startsWith("image/"),exts:[".png",".jpg",".jpeg",".gif",".webp",".bmp",".svg",".avif"]},{icon:svgDocumentIcon("PDF","#ffd7d7"),typeMatch:t=>t==="application/pdf",exts:[".pdf"]},{icon:svgDocumentIcon("AUD","#e6dcff"),typeMatch:t=>t.startsWith("audio/"),exts:[".mp3",".wav",".m4a",".flac"]},{icon:svgDocumentIcon("VID","#dff7ff"),typeMatch:t=>t.startsWith("video/"),exts:[".mp4",".mov",".webm",".mkv"]},{icon:svgDocumentIcon("DOC","#dfe6ff"),typeMatch:t=>["application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document"].includes(t),exts:[".doc",".docx",".odt"]},{icon:svgDocumentIcon("XLS","#e4ffd7"),typeMatch:t=>["text/csv","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"].includes(t),exts:[".xls",".xlsx",".ods",".csv"]},{icon:svgDocumentIcon("ZIP","#fffed7"),typeMatch:t=>t.includes("zip")||t==="application/x-zip-compressed",exts:[".zip",".tar",".gz"]},{icon:svgDocumentIcon("TXT","#eaeaea"),typeMatch:t=>t.startsWith("text/"),exts:[".txt",".md",".log"]}];export class BrowseJS{constructor(container,files=[],opts={}){if(container instanceof Element){this.container=container}else{const containerElement=document.getElementById(container)||document.querySelector(container);if(!containerElement)throw new Error("Container not found: "+container);this.container=containerElement}this.opts=opts;this.iconRules=opts.icons&&opts.icons.rules?opts.icons.rules:DEFAULT_ICON_RULES;this.folderIcon=opts.icons&&opts.icons.folder?opts.icons.folder:svgFolderIcon("");this.defaultIcon=opts.icons&&opts.icons.default?opts.icons.default:svgDocumentIcon("?","#e9eefc");this.multi=Boolean(opts.multiSelect);this.selectedIndices=new Set;this.stack=[{name:opts.rootName||"Root",files:files}];this.breadcrumbEl=document.createElement("nav");this.breadcrumbEl.className="breadcrumb";this.breadcrumbEl.setAttribute("aria-label","Breadcrumb");this.crumbsWrap=document.createElement("div");this.crumbsWrap.className="crumbs-wrap";this.controlsEl=document.createElement("div");this.controlsEl.className="crumb-controls";this.breadcrumbEl.appendChild(this.crumbsWrap);this.breadcrumbEl.appendChild(this.controlsEl);this.detailsEl=document.createElement("aside");this.detailsEl.className="details";this.detailsEl.setAttribute("aria-live","polite");this.detailsEl.textContent=opts.detailsText||"Select a file";this.container.innerHTML="";this.galleryEl=document.createElement("div");this.galleryEl.className="gallery-grid";this.container.appendChild(this.breadcrumbEl);this.container.appendChild(this.galleryEl);this.container.appendChild(this.detailsEl);this._fileInput=document.createElement("input");this._fileInput.type="file";this._fileInput.style.display="none";this.container.appendChild(this._fileInput);this.container.classList.add("browsejs");this.galleryEl.tabIndex=0;document.addEventListener("dragover",e=>{e.preventDefault();this.container.classList.add("dragover")});document.addEventListener("dragleave",e=>{this.container.classList.remove("dragover")});this.container.addEventListener("drop",e=>{e.preventDefault();this.container.classList.remove("dragover");const files=Array.from(e.dataTransfer&&e.dataTransfer.files||[]);if(files.length===0)return;this.handleDropFiles(files)});this.render()}getIconForItem(item){if(item.children)return this.folderIcon;const type=item.meta&&item.meta.type?String(item.meta.type).toLowerCase():"";const name=item.name?String(item.name).toLowerCase():"";if(type){for(const r of this.iconRules){if(r.typeMatch&&r.typeMatch(type))return r.icon}}for(const r of this.iconRules){if(r.exts){for(const e of r.exts){if(name.endsWith(e))return r.icon}}}return this.defaultIcon}render(){this.galleryEl.innerHTML="";const list=this.currentFiles();list.forEach((f,i)=>{const card=document.createElement("button");card.className="card";card.type="button";card.dataset.index=i;card.title=f.name;const img=document.createElement("img");img.alt=f.name||"";img.src=f.thumbnail||this.getIconForItem(f);const meta=document.createElement("div");meta.className="meta";meta.textContent=f.name;card.appendChild(img);card.appendChild(meta);if(f.children&&Array.isArray(f.children)){card.addEventListener("click",()=>this.enterFolder(i));card.addEventListener("keyup",e=>{if(e.key==="Enter")this.enterFolder(i)})}else{card.addEventListener("click",()=>this.select(i));card.addEventListener("keyup",e=>{if(e.key==="Enter")this.select(i)})}this.galleryEl.appendChild(card)});this.updateSelectionUI();this.renderBreadcrumb()}updateSelectionUI(){const cards=this.galleryEl.querySelectorAll(".card");cards.forEach(c=>{const idx=Number(c.dataset.index);if(this.selectedIndices.has(idx))c.classList.add("selected");else c.classList.remove("selected")});this.renderDetails()}renderDetails(){if(!this.detailsEl)return;const activeList=this.currentFiles();if(this.selectedIndices.size===0){this.detailsEl.innerHTML='<p class="small">No selection</p>'}else if(this.selectedIndices.size>1){const indices=Array.from(this.selectedIndices).sort();this.detailsEl.innerHTML="";const header=document.createElement("div");header.innerHTML=`<strong>${indices.length} item${indices.length>1?"s":""} selected</strong>`;this.detailsEl.appendChild(header);const list=document.createElement("div");list.className="small";list.innerHTML=indices.map(i=>`<div>${escapeText(activeList[i]&&activeList[i].name||"Untitled")}</div>`).join("");this.detailsEl.appendChild(list)}else{const index=Array.from(this.selectedIndices)[0];const item=activeList[index];if(!item){this.detailsEl.innerHTML='<p class="small">No selection</p>';return}this.detailsEl.innerHTML="";const img=document.createElement("img");img.className="preview";img.src=item.thumbnail||this.galleryEl.querySelector(`.card[data-index="${index}"] img`)?.src||this.getIconForItem(item);img.alt=item.name||"preview";const name=document.createElement("div");name.innerHTML=`<strong>${item.name||"Untitled"}</strong>`;const meta=document.createElement("div");meta.className="small";if(item.meta&&typeof item.meta==="object"){meta.innerHTML=Object.entries(item.meta).map(([k,v])=>`<div><strong>${k}:</strong> ${v}</div>`).join("")}else if(item.meta){meta.textContent=String(item.meta)}else{meta.textContent=""}this.detailsEl.appendChild(img);this.detailsEl.appendChild(name);this.detailsEl.appendChild(meta)}}renderBreadcrumb(){if(!this.breadcrumbEl)return;this.crumbsWrap.innerHTML="";this.stack.forEach((s,idx)=>{const btn=document.createElement("button");btn.type="button";btn.className="crumb";btn.textContent=s.name;btn.addEventListener("click",()=>this.goToCrumb(idx));this.crumbsWrap.appendChild(btn);if(idx<this.stack.length-1){const sep=document.createElement("span");sep.className="sep";sep.textContent="»";this.crumbsWrap.appendChild(sep)}});this.controlsEl.innerHTML="";const hasCreate=typeof this.opts.onCreateFolder==="function";const hasUpload=typeof this.opts.onUpload==="function";if(hasCreate){const createBtn=document.createElement("button");createBtn.type="button";createBtn.className="crumb-action";createBtn.textContent="New Folder";createBtn.addEventListener("click",()=>this.handleCreateFolder());this.controlsEl.appendChild(createBtn)}if(hasUpload){const uploadBtn=document.createElement("button");uploadBtn.type="button";uploadBtn.className="crumb-action";uploadBtn.textContent="Upload";uploadBtn.addEventListener("click",()=>this.handleUpload());this.controlsEl.appendChild(uploadBtn)}}currentFolder(){return this.stack.map(s=>s.name+"/").slice(1).join()}currentFiles(){return this.stack[this.stack.length-1].files}addFiles(files){if(!Array.isArray(files))files=[files];const current=this.currentFiles();current.push(...files);this.render()}getSelectedPaths(){const activeList=this.currentFiles();const basePath=this.currentFolder();const paths=[];Array.from(this.selectedIndices).forEach(i=>{const item=activeList[i];if(item){paths.push(basePath+item.name)}});return paths}async handleCreateFolder(){if(this._creatingFolder)return;this._creatingFolder=true;const current=this.currentFiles();const card=document.createElement("div");card.className="card creating";card.tabIndex=0;const img=document.createElement("img");img.alt="Folder";img.src=this.folderIcon;const meta=document.createElement("div");meta.className="meta";const nameEl=document.createElement("div");nameEl.className="editable-name";nameEl.contentEditable="true";nameEl.spellcheck=false;nameEl.textContent="";meta.appendChild(nameEl);card.appendChild(img);card.appendChild(meta);this.galleryEl.insertBefore(card,this.galleryEl.firstChild);nameEl.focus();try{const sel=window.getSelection();const range=document.createRange();range.selectNodeContents(nameEl);sel.removeAllRanges();sel.addRange(range)}catch(e){}const cleanup=()=>{this._creatingFolder=false;if(card.parentNode)card.parentNode.removeChild(card)};const commit=async()=>{const name=nameEl.textContent.trim();if(!name){cleanup();return}if(typeof this.opts.onCreateFolder==="function"){const res=await this.opts.onCreateFolder(name);if(res){current.splice(0,0,res)}else{cleanup();return}}else{current.splice(0,0,{name:name,children:[]})}this._creatingFolder=false;this.render()};const onKey=e=>{if(e.key==="Enter"){e.preventDefault();nameEl.blur()}else if(e.key==="Escape"){e.preventDefault();cleanup()}};nameEl.addEventListener("keydown",onKey);nameEl.addEventListener("blur",()=>{setTimeout(()=>{if(!this._creatingFolder)return;commit()},0)},{once:true})}async handleUpload(){if(typeof this.opts.onUpload!=="function")return;this._fileInput.value="";this._fileInput.multiple=true;this._fileInput.onchange=async()=>{const files=Array.from(this._fileInput.files||[]);if(files.length===0)return;try{const res=await this.opts.onUpload(files);if(res){const current=this.currentFiles();if(Array.isArray(res))current.push(...res);else current.push(res);this.render()}}catch(err){console.error("onUpload error",err)}};this._fileInput.click()}async handleDropFiles(files){if(!files||files.length===0)return;if(typeof this.opts.onUpload!=="function")return;try{const res=await this.opts.onUpload(files);if(res){const current=this.currentFiles();if(Array.isArray(res))current.push(...res);else current.push(res);this.render()}}catch(err){console.error("onUpload error",err)}}select(i){const activeList=this.currentFiles();if(this.multi){if(this.selectedIndices.has(i)){this.selectedIndices.delete(i)}else{this.selectedIndices.add(i)}}else{if(this.selectedIndices.has(i)){this.selectedIndices.clear()}else{this.selectedIndices.clear();this.selectedIndices.add(i)}}this.updateSelectionUI();if(typeof this.opts.onSelect==="function"){const indices=Array.from(this.selectedIndices).sort((a,b)=>a-b);const items=indices.map(idx=>activeList[idx]);this.opts.onSelect(items,indices)}}enterFolder(i){const f=this.currentFiles()[i];if(!f||!Array.isArray(f.children))return;this.stack.push({name:f.name||"Folder",files:f.children});this.selectedIndices.clear();this.render()}goToCrumb(idx){this.stack=this.stack.slice(0,idx+1);this.selectedIndices.clear();this.render()}}
@@ -0,0 +1 @@
1
+ function svgDataUrlFromSvg(svg){return"data:image/svg+xml;utf8,"+encodeURIComponent(svg)}function escapeText(t){return String(t).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function svgDocumentIcon(label,bg="#e9eefc",w=240,h=310){return svgDataUrlFromSvg(`<?xml version='1.0' encoding='utf-8'?><svg xmlns='http://www.w3.org/2000/svg' width='${w}' height='${h}' viewBox='0 0 ${w} ${h}'><path d='${`M0 0 H${w-84} L${w} 84 V${h} H0 Z`}' fill='${bg}' stroke='#0b12200a' stroke-linejoin='round'/><path d='${`M${w-84} 0 v84 h84 Z`}' fill='#0000001a' stroke='#0b122005'/><text x='50%' y='58%' dominant-baseline='middle' text-anchor='middle' font-family='Inter,Arial,Helvetica,sans-serif' font-size='36' fill='#0b1220'>${escapeText(label||"")}</text></svg>`)}function svgFolderIcon(label,bg="#ffd7a8",w=420,h=320){return svgDataUrlFromSvg(`<?xml version='1.0' encoding='utf-8'?><svg xmlns='http://www.w3.org/2000/svg' width='${w}' height='${h}' viewBox='0 0 ${w} ${h}'><rect x='6' y='34' rx='12' ry='12' width='${w-12}' height='${h-40}' fill='${bg}' stroke='#0b12200a'/><rect x='18' y='12' rx='8' ry='8' width='120' height='44' fill='${bg}'/><text x='50%' y='62%' dominant-baseline='middle' text-anchor='middle' font-family='Inter,Arial,Helvetica,sans-serif' font-size='36' fill='#0b1220'>${escapeText(label||"")}</text></svg>`)}const DEFAULT_ICON_RULES=[{icon:svgDocumentIcon("IMG","#c7ddff"),typeMatch:t=>t.startsWith("image/"),exts:[".png",".jpg",".jpeg",".gif",".webp",".bmp",".svg",".avif"]},{icon:svgDocumentIcon("PDF","#ffd7d7"),typeMatch:t=>"application/pdf"===t,exts:[".pdf"]},{icon:svgDocumentIcon("AUD","#e6dcff"),typeMatch:t=>t.startsWith("audio/"),exts:[".mp3",".wav",".m4a",".flac"]},{icon:svgDocumentIcon("VID","#dff7ff"),typeMatch:t=>t.startsWith("video/"),exts:[".mp4",".mov",".webm",".mkv"]},{icon:svgDocumentIcon("DOC","#dfe6ff"),typeMatch:t=>["application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document"].includes(t),exts:[".doc",".docx",".odt"]},{icon:svgDocumentIcon("XLS","#e4ffd7"),typeMatch:t=>["text/csv","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"].includes(t),exts:[".xls",".xlsx",".ods",".csv"]},{icon:svgDocumentIcon("ZIP","#fffed7"),typeMatch:t=>t.includes("zip")||"application/x-zip-compressed"===t,exts:[".zip",".tar",".gz"]},{icon:svgDocumentIcon("TXT","#eaeaea"),typeMatch:t=>t.startsWith("text/"),exts:[".txt",".md",".log"]}];export class BrowseJS{constructor(container,files=[],opts={}){if(container instanceof Element)this.container=container;else{const containerElement=document.getElementById(container)||document.querySelector(container);if(!containerElement)throw new Error("Container not found: "+container);this.container=containerElement}this.opts=opts,this.iconRules=opts.icons&&opts.icons.rules?opts.icons.rules:DEFAULT_ICON_RULES,this.folderIcon=opts.icons&&opts.icons.folder?opts.icons.folder:svgFolderIcon(""),this.defaultIcon=opts.icons&&opts.icons.default?opts.icons.default:svgDocumentIcon("?","#e9eefc"),this.multi=Boolean(opts.multiSelect),this.selectedIndices=new Set,this.stack=[{name:opts.rootName||"Root",files:files}],this.breadcrumbEl=document.createElement("nav"),this.breadcrumbEl.className="breadcrumb",this.breadcrumbEl.setAttribute("aria-label","Breadcrumb"),this.crumbsWrap=document.createElement("div"),this.crumbsWrap.className="crumbs-wrap",this.controlsEl=document.createElement("div"),this.controlsEl.className="crumb-controls",this.breadcrumbEl.appendChild(this.crumbsWrap),this.breadcrumbEl.appendChild(this.controlsEl),this.detailsEl=document.createElement("aside"),this.detailsEl.className="details",this.detailsEl.setAttribute("aria-live","polite"),this.detailsEl.textContent=opts.detailsText||"Select a file",this.container.innerHTML="",this.galleryEl=document.createElement("div"),this.galleryEl.className="gallery-grid",this.container.appendChild(this.breadcrumbEl),this.container.appendChild(this.galleryEl),this.container.appendChild(this.detailsEl),this._fileInput=document.createElement("input"),this._fileInput.type="file",this._fileInput.style.display="none",this.container.appendChild(this._fileInput),this.container.classList.add("browsejs"),this.galleryEl.tabIndex=0,document.addEventListener("dragover",e=>{e.preventDefault(),this.container.classList.add("dragover")}),document.addEventListener("dragleave",e=>{this.container.classList.remove("dragover")}),this.container.addEventListener("drop",e=>{e.preventDefault(),this.container.classList.remove("dragover");const files=Array.from(e.dataTransfer&&e.dataTransfer.files||[]);0!==files.length&&this.handleDropFiles(files)}),this.render()}getIconForItem(item){if(item.children)return this.folderIcon;const type=item.meta&&item.meta.type?String(item.meta.type).toLowerCase():"",name=item.name?String(item.name).toLowerCase():"";if(type)for(const r of this.iconRules)if(r.typeMatch&&r.typeMatch(type))return r.icon;for(const r of this.iconRules)if(r.exts)for(const e of r.exts)if(name.endsWith(e))return r.icon;return this.defaultIcon}render(){this.galleryEl.innerHTML="";this.currentFiles().forEach((f,i)=>{const card=document.createElement("button");card.className="card",card.type="button",card.dataset.index=i,card.title=f.name;const img=document.createElement("img");img.alt=f.name||"",img.src=f.thumbnail||this.getIconForItem(f);const meta=document.createElement("div");meta.className="meta",meta.textContent=f.name,card.appendChild(img),card.appendChild(meta),f.children&&Array.isArray(f.children)?(card.addEventListener("click",()=>this.enterFolder(i)),card.addEventListener("keyup",e=>{"Enter"===e.key&&this.enterFolder(i)})):(card.addEventListener("click",()=>this.select(i)),card.addEventListener("keyup",e=>{"Enter"===e.key&&this.select(i)})),this.galleryEl.appendChild(card)}),this.updateSelectionUI(),this.renderBreadcrumb()}updateSelectionUI(){this.galleryEl.querySelectorAll(".card").forEach(c=>{const idx=Number(c.dataset.index);this.selectedIndices.has(idx)?c.classList.add("selected"):c.classList.remove("selected")}),this.renderDetails()}renderDetails(){if(!this.detailsEl)return;const activeList=this.currentFiles();if(0===this.selectedIndices.size)this.detailsEl.innerHTML='<p class="small">No selection</p>';else if(this.selectedIndices.size>1){const indices=Array.from(this.selectedIndices).sort();this.detailsEl.innerHTML="";const header=document.createElement("div");header.innerHTML=`<strong>${indices.length} item${indices.length>1?"s":""} selected</strong>`,this.detailsEl.appendChild(header);const list=document.createElement("div");list.className="small",list.innerHTML=indices.map(i=>`<div>${escapeText(activeList[i]&&activeList[i].name||"Untitled")}</div>`).join(""),this.detailsEl.appendChild(list)}else{const index=Array.from(this.selectedIndices)[0],item=activeList[index];if(!item)return void(this.detailsEl.innerHTML='<p class="small">No selection</p>');this.detailsEl.innerHTML="";const img=document.createElement("img");img.className="preview",img.src=item.thumbnail||this.galleryEl.querySelector(`.card[data-index="${index}"] img`)?.src||this.getIconForItem(item),img.alt=item.name||"preview";const name=document.createElement("div");name.innerHTML=`<strong>${item.name||"Untitled"}</strong>`;const meta=document.createElement("div");meta.className="small",item.meta&&"object"==typeof item.meta?meta.innerHTML=Object.entries(item.meta).map(([k,v])=>`<div><strong>${k}:</strong> ${v}</div>`).join(""):item.meta?meta.textContent=String(item.meta):meta.textContent="",this.detailsEl.appendChild(img),this.detailsEl.appendChild(name),this.detailsEl.appendChild(meta)}}renderBreadcrumb(){if(!this.breadcrumbEl)return;this.crumbsWrap.innerHTML="",this.stack.forEach((s,idx)=>{const btn=document.createElement("button");if(btn.type="button",btn.className="crumb",btn.textContent=s.name,btn.addEventListener("click",()=>this.goToCrumb(idx)),this.crumbsWrap.appendChild(btn),idx<this.stack.length-1){const sep=document.createElement("span");sep.className="sep",sep.textContent="»",this.crumbsWrap.appendChild(sep)}}),this.controlsEl.innerHTML="";const hasCreate="function"==typeof this.opts.onCreateFolder,hasUpload="function"==typeof this.opts.onUpload;if(hasCreate){const createBtn=document.createElement("button");createBtn.type="button",createBtn.className="crumb-action",createBtn.textContent="New Folder",createBtn.addEventListener("click",()=>this.handleCreateFolder()),this.controlsEl.appendChild(createBtn)}if(hasUpload){const uploadBtn=document.createElement("button");uploadBtn.type="button",uploadBtn.className="crumb-action",uploadBtn.textContent="Upload",uploadBtn.addEventListener("click",()=>this.handleUpload()),this.controlsEl.appendChild(uploadBtn)}}currentFolder(){return this.stack.map(s=>s.name+"/").slice(1).join()}currentFiles(){return this.stack[this.stack.length-1].files}addFiles(files){Array.isArray(files)||(files=[files]);this.currentFiles().push(...files),this.render()}getSelectedPaths(){const activeList=this.currentFiles(),basePath=this.currentFolder(),paths=[];return Array.from(this.selectedIndices).forEach(i=>{const item=activeList[i];item&&paths.push(basePath+item.name)}),paths}async handleCreateFolder(){if(this._creatingFolder)return;this._creatingFolder=!0;const current=this.currentFiles(),card=document.createElement("div");card.className="card creating",card.tabIndex=0;const img=document.createElement("img");img.alt="Folder",img.src=this.folderIcon;const meta=document.createElement("div");meta.className="meta";const nameEl=document.createElement("div");nameEl.className="editable-name",nameEl.contentEditable="true",nameEl.spellcheck=!1,nameEl.textContent="",meta.appendChild(nameEl),card.appendChild(img),card.appendChild(meta),this.galleryEl.insertBefore(card,this.galleryEl.firstChild),nameEl.focus();try{const sel=window.getSelection(),range=document.createRange();range.selectNodeContents(nameEl),sel.removeAllRanges(),sel.addRange(range)}catch(e){}const cleanup=()=>{this._creatingFolder=!1,card.parentNode&&card.parentNode.removeChild(card)},commit=async()=>{const name=nameEl.textContent.trim();if(name){if("function"==typeof this.opts.onCreateFolder){const res=await this.opts.onCreateFolder(name);if(!res)return void cleanup();current.splice(0,0,res)}else current.splice(0,0,{name:name,children:[]});this._creatingFolder=!1,this.render()}else cleanup()};nameEl.addEventListener("keydown",e=>{"Enter"===e.key?(e.preventDefault(),nameEl.blur()):"Escape"===e.key&&(e.preventDefault(),cleanup())}),nameEl.addEventListener("blur",()=>{setTimeout(()=>{this._creatingFolder&&commit()},0)},{once:!0})}async handleUpload(){"function"==typeof this.opts.onUpload&&(this._fileInput.value="",this._fileInput.multiple=!0,this._fileInput.onchange=async()=>{const files=Array.from(this._fileInput.files||[]);if(0!==files.length)try{const res=await this.opts.onUpload(files);if(res){const current=this.currentFiles();Array.isArray(res)?current.push(...res):current.push(res),this.render()}}catch(err){console.error("onUpload error",err)}},this._fileInput.click())}async handleDropFiles(files){if(files&&0!==files.length&&"function"==typeof this.opts.onUpload)try{const res=await this.opts.onUpload(files);if(res){const current=this.currentFiles();Array.isArray(res)?current.push(...res):current.push(res),this.render()}}catch(err){console.error("onUpload error",err)}}select(i){const activeList=this.currentFiles();if(this.multi?this.selectedIndices.has(i)?this.selectedIndices.delete(i):this.selectedIndices.add(i):this.selectedIndices.has(i)?this.selectedIndices.clear():(this.selectedIndices.clear(),this.selectedIndices.add(i)),this.updateSelectionUI(),"function"==typeof this.opts.onSelect){const indices=Array.from(this.selectedIndices).sort((a,b)=>a-b),items=indices.map(idx=>activeList[idx]);this.opts.onSelect(items,indices)}}enterFolder(i){const f=this.currentFiles()[i];f&&Array.isArray(f.children)&&(this.stack.push({name:f.name||"Folder",files:f.children}),this.selectedIndices.clear(),this.render())}goToCrumb(idx){this.stack=this.stack.slice(0,idx+1),this.selectedIndices.clear(),this.render()}}
package/dist/style.css ADDED
@@ -0,0 +1,111 @@
1
+ .browsejs {
2
+ --gap: 12px;
3
+ --selection-color: #2348d6;
4
+ display: grid;
5
+ grid-template-columns: 1fr 280px;
6
+ grid-template-rows: auto 1fr;
7
+ grid-template-areas: "breadcrumb breadcrumb" "gallery details";
8
+ gap: var(--gap);
9
+ }
10
+ .browsejs button {
11
+ font-family: inherit;
12
+ }
13
+ .browsejs .card {
14
+ background: transparent;
15
+ border: none;
16
+ overflow: hidden;
17
+ cursor: pointer;
18
+ display: flex;
19
+ flex-direction: column;
20
+ align-items: stretch;
21
+ }
22
+ .browsejs .card img {
23
+ width: 100%;
24
+ height: 160px;
25
+ object-fit: contain;
26
+ display: block;
27
+ }
28
+ .browsejs .card .meta {
29
+ padding: 3px;
30
+ font-size: 13px;
31
+ color: #0b1220;
32
+ white-space: nowrap;
33
+ overflow: hidden;
34
+ text-overflow: ellipsis;
35
+ }
36
+ .browsejs .card .editable-name {
37
+ padding: 3px;
38
+ }
39
+ .browsejs .card.selected {
40
+ border-color: var(--selection-color);
41
+ box-shadow: 0 6px 18px #2463ff1f;
42
+ }
43
+ .browsejs .gallery-grid {
44
+ box-sizing: border-box;
45
+ border: 2px dotted transparent;
46
+ grid-area: gallery;
47
+ display: grid;
48
+ grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
49
+ grid-auto-rows: max-content;
50
+ gap: var(--gap);
51
+ padding: var(--gap);
52
+ overflow-y: auto;
53
+ }
54
+ .browsejs .details {
55
+ background: #fff;
56
+ border-radius: 8px;
57
+ padding: var(--gap);
58
+ min-height: 140px;
59
+ grid-area: details;
60
+ }
61
+ .browsejs .preview {
62
+ width: 100%;
63
+ height: 180px;
64
+ object-fit: contain;
65
+ background: #e9eefc;
66
+ border-radius: 6px;
67
+ display: block;
68
+ margin-bottom: 10px;
69
+ }
70
+ .browsejs .small {
71
+ font-size: 13px;
72
+ color: #475569;
73
+ }
74
+ .browsejs .breadcrumb {
75
+ display: flex;
76
+ gap: 8px;
77
+ align-items: center;
78
+ justify-content: space-between;
79
+ margin-top: 8px;
80
+ grid-area: breadcrumb;
81
+ }
82
+ .browsejs .breadcrumb .crumb {
83
+ background: transparent;
84
+ border: 0;
85
+ padding: 4px 6px;
86
+ cursor: pointer;
87
+ color: var(--selection-color);
88
+ }
89
+ .browsejs .breadcrumb .crumb:hover {
90
+ background: #2463ff0f;
91
+ }
92
+ .browsejs .breadcrumb .sep {
93
+ color: #94a3b8;
94
+ }
95
+ .browsejs.dragover .gallery-grid {
96
+ border-color: var(--selection-color);
97
+ }
98
+ .browsejs.dragover .gallery-grid .card {
99
+ opacity: 0.7;
100
+ }
101
+ @media (max-width: 800px) {
102
+ .browsejs {
103
+ padding: 0 10px;
104
+ grid-template-columns: 1fr;
105
+ grid-template-rows: auto 1fr max-content;
106
+ grid-template-areas: "breadcrumb" "gallery" "details";
107
+ }
108
+ .browsejs .details {
109
+ min-height: initial;
110
+ }
111
+ }
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "browse.js",
3
+ "version": "0.0.1",
4
+ "description": "A lightweight yet versatile file browser written in vanilla JS.",
5
+ "keywords": [
6
+ "file",
7
+ "browser",
8
+ "chooser",
9
+ "widget"
10
+ ],
11
+ "homepage": "https://github.com/pydsigner/browse.js#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/pydsigner/browse.js/issues"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/pydsigner/browse.js.git"
18
+ },
19
+ "license": "Apache-2.0",
20
+ "author": "Daniel Foerster <df@d48.io> (https://d48.io)",
21
+ "type": "commonjs",
22
+ "main": "dist/browse.js",
23
+ "scripts": {
24
+ "build": "tsc && terser src/browse.js -o dist/browse.js && terser src/browse.js -c -o dist/browse.min.js && lessc src/style.less dist/style.css",
25
+ "test": "echo \"Error: no test specified\" && exit 1"
26
+ },
27
+ "devDependencies": {
28
+ "less": "^4.5.1",
29
+ "terser": "^5.46.0",
30
+ "typescript": "^5.9.3"
31
+ }
32
+ }
package/src/browse.js ADDED
@@ -0,0 +1,475 @@
1
+ // Create a data URL from raw SVG markup
2
+ function svgDataUrlFromSvg(svg) {
3
+ return 'data:image/svg+xml;utf8,' + encodeURIComponent(svg);
4
+ }
5
+
6
+ function escapeText(t) {
7
+ return String(t).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
8
+ }
9
+
10
+ function svgDocumentIcon(label, bg = '#e9eefc', w = 240, h = 310) {
11
+ const safe = escapeText(label || '');
12
+ const fold = 84;
13
+
14
+ // Draw page body leaving out the folded corner area
15
+ const bodyPath = `M0 0 H${w - fold} L${w} ${fold} V${h} H0 Z`;
16
+ // Draw the folded corner as a darker layer on top
17
+ const foldPath = `M${w - fold} 0 v${fold} h${fold} Z`;
18
+
19
+ const svg = `<?xml version='1.0' encoding='utf-8'?><svg xmlns='http://www.w3.org/2000/svg' width='${w}' height='${h}' viewBox='0 0 ${w} ${h}'>` +
20
+ `<path d='${bodyPath}' fill='${bg}' stroke='#0b12200a' stroke-linejoin='round'/>` +
21
+ `<path d='${foldPath}' fill='#0000001a' stroke='#0b122005'/>` +
22
+ `<text x='50%' y='58%' dominant-baseline='middle' text-anchor='middle' font-family='Inter,Arial,Helvetica,sans-serif' font-size='36' fill='#0b1220'>${safe}</text>` +
23
+ `</svg>`;
24
+ return svgDataUrlFromSvg(svg);
25
+ }
26
+
27
+ function svgFolderIcon(label, bg = '#ffd7a8', w = 420, h = 320) {
28
+ const safe = escapeText(label || '');
29
+ const tabH = 44;
30
+ const tabW = 120;
31
+ const svg = `<?xml version='1.0' encoding='utf-8'?><svg xmlns='http://www.w3.org/2000/svg' width='${w}' height='${h}' viewBox='0 0 ${w} ${h}'>` +
32
+ `<rect x='6' y='34' rx='12' ry='12' width='${w - 12}' height='${h - 40}' fill='${bg}' stroke='#0b12200a'/>` +
33
+ `<rect x='18' y='12' rx='8' ry='8' width='${tabW}' height='${tabH}' fill='${bg}'/>` +
34
+ `<text x='50%' y='62%' dominant-baseline='middle' text-anchor='middle' font-family='Inter,Arial,Helvetica,sans-serif' font-size='36' fill='#0b1220'>${safe}</text>` +
35
+ `</svg>`;
36
+ return svgDataUrlFromSvg(svg);
37
+ }
38
+
39
+ const DEFAULT_ICON_RULES = [
40
+ { icon: svgDocumentIcon('IMG', '#c7ddff'), typeMatch: t => t.startsWith('image/'), exts: ['.png', '.jpg', '.jpeg', '.gif', '.webp', '.bmp', '.svg', '.avif'] },
41
+ { icon: svgDocumentIcon('PDF', '#ffd7d7'), typeMatch: t => t === 'application/pdf', exts: ['.pdf'] },
42
+ { icon: svgDocumentIcon('AUD', '#e6dcff'), typeMatch: t => t.startsWith('audio/'), exts: ['.mp3', '.wav', '.m4a', '.flac'] },
43
+ { icon: svgDocumentIcon('VID', '#dff7ff'), typeMatch: t => t.startsWith('video/'), exts: ['.mp4', '.mov', '.webm', '.mkv'] },
44
+ { icon: svgDocumentIcon('DOC', '#dfe6ff'), typeMatch: t => ['application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'].includes(t), exts: ['.doc', '.docx', '.odt'] },
45
+ { icon: svgDocumentIcon('XLS', '#e4ffd7'), typeMatch: t => ['text/csv', 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'].includes(t), exts: ['.xls', '.xlsx', '.ods', '.csv'] },
46
+ { icon: svgDocumentIcon('ZIP', '#fffed7'), typeMatch: t => t.includes('zip') || t === 'application/x-zip-compressed', exts: ['.zip', '.tar', '.gz'] },
47
+ { icon: svgDocumentIcon('TXT', '#eaeaea'), typeMatch: t => t.startsWith('text/'), exts: ['.txt', '.md', '.log'] },
48
+ ];
49
+
50
+
51
+ /**
52
+ * @typedef {Object} IconRule
53
+ * @property {string} icon - The icon URL
54
+ * @property {function(string):boolean} [typeMatch] - Optional function to match against the MIME type of a file
55
+ * @property {string[]} [exts] - Optional array of file extensions (with dot) to match against the file name
56
+ */
57
+
58
+ /**
59
+ * @typedef {Object} FileItem
60
+ * @property {string} name - The display name of the file or folder
61
+ * @property {string} [thumbnail] - Optional data URL for the thumbnail image
62
+ * @property {Object} [meta] - Optional metadata object with additional info (e.g. size, type)
63
+ * @property {FileItem[]} [children] - If present, indicates this item is a folder containing these child items
64
+ */
65
+
66
+ /**
67
+ * @typedef {Object} BrowseJSOptions
68
+ * @property {string} [rootName] - The display name for the root folder (default: "Root")
69
+ * @property {function(FileItem, number):void} [onSelect] - Callback when a file is selected, receives the file item and its index
70
+ * @property {string} [detailsText] - Default text to show in the details pane when no selection is made (default: "Select a file")
71
+ * @property {Object} [icons] - Custom icons configuration
72
+ * @property {IconRule[]} [icons.rules] - Custom rules for determining icons based on MIME type or file extension
73
+ * @property {string} [icons.folder] - Custom icon URL for folders
74
+ * @property {string} [icons.default] - Custom icon URL for files that don't match any rule
75
+ * @property {boolean} [multiSelect] - If true, allows selecting multiple files (default: false)
76
+ * @property {function(string):?(FileItem)} [onCreateFolder] - Optional callback invoked when creating a new folder. If it returns a FileItem, it will be added to the current folder.
77
+ * @property {function(File[]):?(FileItem|FileItem[])} [onUpload] - Optional callback invoked when files are uploaded. If it returns FileItem(s), they'll be added to the current folder.
78
+ */
79
+
80
+ export class BrowseJS {
81
+ /**
82
+ * @param {string|Element} container - The the container element to render the gallery into. Can be a DOM element, ID, or selector string.
83
+ * @param {FileItem[]} files - An array of file items to display in the root folder
84
+ * @param {BrowseJSOptions} opts - Configuration options (see BrowseJSOptions typedef for details)
85
+ */
86
+ constructor(container, files = [], opts = {}) {
87
+ if (container instanceof Element) { this.container = container; }
88
+ else {
89
+ const containerElement = document.getElementById(container) || document.querySelector(container);
90
+ if (!containerElement) throw new Error('Container not found: ' + container);
91
+ this.container = containerElement;
92
+ }
93
+ this.opts = opts;
94
+ this.iconRules = opts.icons && opts.icons.rules ? opts.icons.rules : DEFAULT_ICON_RULES;
95
+ this.folderIcon = opts.icons && opts.icons.folder ? opts.icons.folder : svgFolderIcon('');
96
+ this.defaultIcon = opts.icons && opts.icons.default ? opts.icons.default : svgDocumentIcon('?', '#e9eefc');
97
+ this.multi = Boolean(opts.multiSelect);
98
+ this.selectedIndices = new Set();
99
+ this.stack = [{ name: opts.rootName || 'Root', files }];
100
+
101
+ // create breadcrumb and details elements and insert around the gallery container
102
+ this.breadcrumbEl = document.createElement('nav');
103
+ this.breadcrumbEl.className = 'breadcrumb';
104
+ this.breadcrumbEl.setAttribute('aria-label', 'Breadcrumb');
105
+
106
+ // crumbs wrapper and controls container
107
+ this.crumbsWrap = document.createElement('div');
108
+ this.crumbsWrap.className = 'crumbs-wrap';
109
+ this.controlsEl = document.createElement('div');
110
+ this.controlsEl.className = 'crumb-controls';
111
+ this.breadcrumbEl.appendChild(this.crumbsWrap);
112
+ this.breadcrumbEl.appendChild(this.controlsEl);
113
+
114
+ this.detailsEl = document.createElement('aside');
115
+ this.detailsEl.className = 'details';
116
+ this.detailsEl.setAttribute('aria-live', 'polite');
117
+ this.detailsEl.textContent = opts.detailsText || 'Select a file';
118
+
119
+ // Insert breadcrumb, gallery grid and details inside the gallery container
120
+ this.container.innerHTML = '';
121
+ this.galleryEl = document.createElement('div');
122
+ this.galleryEl.className = 'gallery-grid';
123
+ this.container.appendChild(this.breadcrumbEl);
124
+ this.container.appendChild(this.galleryEl);
125
+ this.container.appendChild(this.detailsEl);
126
+
127
+ this._fileInput = document.createElement('input');
128
+ this._fileInput.type = 'file';
129
+ this._fileInput.style.display = 'none';
130
+ this.container.appendChild(this._fileInput);
131
+
132
+ // bind events to the inner gallery grid
133
+ this.container.classList.add('browsejs');
134
+ this.galleryEl.tabIndex = 0;
135
+
136
+ // drag & drop support: highlight container on dragover, accept drops
137
+ document.addEventListener('dragover', (e) => {
138
+ e.preventDefault();
139
+ this.container.classList.add('dragover');
140
+ });
141
+ document.addEventListener('dragleave', (e) => {
142
+ this.container.classList.remove('dragover');
143
+ });
144
+ this.container.addEventListener('drop', (e) => {
145
+ e.preventDefault();
146
+ this.container.classList.remove('dragover');
147
+ const files = Array.from((e.dataTransfer && e.dataTransfer.files) || []);
148
+ if (files.length === 0) return;
149
+ this.handleDropFiles(files);
150
+ });
151
+
152
+ this.render();
153
+ }
154
+
155
+ getIconForItem(item) {
156
+ if (item.children) return this.folderIcon;
157
+ const type = item.meta && item.meta.type ? String(item.meta.type).toLowerCase() : '';
158
+ const name = item.name ? String(item.name).toLowerCase() : '';
159
+
160
+ if (type) {
161
+ for (const r of this.iconRules) {
162
+ if (r.typeMatch && r.typeMatch(type)) return r.icon;
163
+ }
164
+ }
165
+ for (const r of this.iconRules) {
166
+ if (r.exts) {
167
+ for (const e of r.exts) {
168
+ if (name.endsWith(e)) return r.icon;
169
+ }
170
+ }
171
+ }
172
+ return this.defaultIcon;
173
+ }
174
+
175
+ render() {
176
+ this.galleryEl.innerHTML = '';
177
+ const list = this.currentFiles();
178
+ list.forEach((f, i) => {
179
+ const card = document.createElement('button');
180
+ card.className = 'card';
181
+ card.type = 'button';
182
+ card.dataset.index = i;
183
+ card.title = f.name;
184
+
185
+ const img = document.createElement('img');
186
+ img.alt = f.name || '';
187
+ img.src = f.thumbnail || this.getIconForItem(f);
188
+
189
+ const meta = document.createElement('div');
190
+ meta.className = 'meta';
191
+ meta.textContent = f.name;
192
+
193
+ card.appendChild(img);
194
+ card.appendChild(meta);
195
+
196
+ if (f.children && Array.isArray(f.children)) {
197
+ card.addEventListener('click', () => this.enterFolder(i));
198
+ card.addEventListener('keyup', (e) => { if (e.key === 'Enter') this.enterFolder(i); });
199
+ } else {
200
+ card.addEventListener('click', () => this.select(i));
201
+ card.addEventListener('keyup', (e) => { if (e.key === 'Enter') this.select(i); });
202
+ }
203
+
204
+ this.galleryEl.appendChild(card);
205
+ });
206
+ this.updateSelectionUI();
207
+ this.renderBreadcrumb();
208
+ }
209
+
210
+ updateSelectionUI() {
211
+ const cards = this.galleryEl.querySelectorAll('.card');
212
+ cards.forEach(c => {
213
+ const idx = Number(c.dataset.index);
214
+ if (this.selectedIndices.has(idx)) c.classList.add('selected');
215
+ else c.classList.remove('selected');
216
+ });
217
+ this.renderDetails();
218
+ }
219
+
220
+ renderDetails() {
221
+ if (!this.detailsEl) return;
222
+ const activeList = this.currentFiles();
223
+ if (this.selectedIndices.size === 0) { this.detailsEl.innerHTML = '<p class="small">No selection</p>'; }
224
+ // If multiple selected, show a simple list and count
225
+ else if (this.selectedIndices.size > 1) {
226
+ const indices = Array.from(this.selectedIndices).sort();
227
+ this.detailsEl.innerHTML = '';
228
+ const header = document.createElement('div');
229
+ header.innerHTML = `<strong>${indices.length} item${indices.length > 1 ? 's' : ''} selected</strong>`;
230
+ this.detailsEl.appendChild(header);
231
+ const list = document.createElement('div');
232
+ list.className = 'small';
233
+ list.innerHTML = indices.map(i => `<div>${escapeText((activeList[i] && activeList[i].name) || 'Untitled')}</div>`).join('');
234
+ this.detailsEl.appendChild(list);
235
+ }
236
+ else {
237
+ const index = Array.from(this.selectedIndices)[0];
238
+ const item = activeList[index];
239
+ if (!item) { this.detailsEl.innerHTML = '<p class="small">No selection</p>'; return; }
240
+ this.detailsEl.innerHTML = '';
241
+ const img = document.createElement('img');
242
+ img.className = 'preview';
243
+ img.src = item.thumbnail || this.galleryEl.querySelector(`.card[data-index="${index}"] img`)?.src || this.getIconForItem(item);
244
+ img.alt = item.name || 'preview';
245
+ const name = document.createElement('div');
246
+ name.innerHTML = `<strong>${item.name || 'Untitled'}</strong>`;
247
+ const meta = document.createElement('div');
248
+ meta.className = 'small';
249
+
250
+ if (item.meta && typeof item.meta === 'object') {
251
+ meta.innerHTML = Object.entries(item.meta).map(([k, v]) => `<div><strong>${k}:</strong> ${v}</div>`).join('');
252
+ } else if (item.meta) {
253
+ meta.textContent = String(item.meta);
254
+ } else {
255
+ meta.textContent = '';
256
+ }
257
+
258
+ this.detailsEl.appendChild(img);
259
+ this.detailsEl.appendChild(name);
260
+ this.detailsEl.appendChild(meta);
261
+ }
262
+ }
263
+
264
+ renderBreadcrumb() {
265
+ if (!this.breadcrumbEl) return;
266
+ this.crumbsWrap.innerHTML = '';
267
+ this.stack.forEach((s, idx) => {
268
+ const btn = document.createElement('button');
269
+ btn.type = 'button';
270
+ btn.className = 'crumb';
271
+ btn.textContent = s.name;
272
+ btn.addEventListener('click', () => this.goToCrumb(idx));
273
+ this.crumbsWrap.appendChild(btn);
274
+ if (idx < this.stack.length - 1) {
275
+ const sep = document.createElement('span'); sep.className = 'sep'; sep.textContent = '»';
276
+ this.crumbsWrap.appendChild(sep);
277
+ }
278
+ });
279
+
280
+ this.controlsEl.innerHTML = '';
281
+ const hasCreate = typeof this.opts.onCreateFolder === 'function';
282
+ const hasUpload = typeof this.opts.onUpload === 'function';
283
+ if (hasCreate) {
284
+ const createBtn = document.createElement('button');
285
+ createBtn.type = 'button';
286
+ createBtn.className = 'crumb-action';
287
+ createBtn.textContent = 'New Folder';
288
+ createBtn.addEventListener('click', () => this.handleCreateFolder());
289
+ this.controlsEl.appendChild(createBtn);
290
+ }
291
+
292
+ if (hasUpload) {
293
+ const uploadBtn = document.createElement('button');
294
+ uploadBtn.type = 'button';
295
+ uploadBtn.className = 'crumb-action';
296
+ uploadBtn.textContent = 'Upload';
297
+ uploadBtn.addEventListener('click', () => this.handleUpload());
298
+ this.controlsEl.appendChild(uploadBtn);
299
+ }
300
+ }
301
+
302
+ currentFolder() {return this.stack.map(s => s.name + '/').slice(1).join();}
303
+
304
+ currentFiles() { return this.stack[this.stack.length - 1].files; }
305
+
306
+ addFiles(files) {
307
+ if (!Array.isArray(files)) files = [files];
308
+ const current = this.currentFiles();
309
+ current.push(...files);
310
+ this.render();
311
+ }
312
+
313
+ getSelectedPaths() {
314
+ const activeList = this.currentFiles();
315
+ const basePath = this.currentFolder();
316
+ const paths = [];
317
+ Array.from(this.selectedIndices).forEach(i => {
318
+ const item = activeList[i];
319
+ if (item) {
320
+ paths.push(basePath + item.name);
321
+ }
322
+ });
323
+ return paths;
324
+ }
325
+
326
+ async handleCreateFolder() {
327
+ if (this._creatingFolder) return;
328
+ this._creatingFolder = true;
329
+
330
+ const current = this.currentFiles();
331
+
332
+ const card = document.createElement('div');
333
+ card.className = 'card creating';
334
+ card.tabIndex = 0;
335
+
336
+ const img = document.createElement('img');
337
+ img.alt = 'Folder';
338
+ img.src = this.folderIcon;
339
+
340
+ const meta = document.createElement('div');
341
+ meta.className = 'meta';
342
+
343
+ const nameEl = document.createElement('div');
344
+ nameEl.className = 'editable-name';
345
+ nameEl.contentEditable = 'true';
346
+ nameEl.spellcheck = false;
347
+ nameEl.textContent = '';
348
+
349
+ meta.appendChild(nameEl);
350
+ card.appendChild(img);
351
+ card.appendChild(meta);
352
+
353
+ this.galleryEl.insertBefore(card, this.galleryEl.firstChild);
354
+
355
+ // focus and select text
356
+ nameEl.focus();
357
+ try {
358
+ const sel = window.getSelection();
359
+ const range = document.createRange();
360
+ range.selectNodeContents(nameEl);
361
+ sel.removeAllRanges();
362
+ sel.addRange(range);
363
+ } catch (e) { /* ignore selection errors */ }
364
+
365
+ const cleanup = () => {
366
+ this._creatingFolder = false;
367
+ if (card.parentNode) card.parentNode.removeChild(card);
368
+ };
369
+
370
+ const commit = async () => {
371
+ const name = nameEl.textContent.trim();
372
+ if (!name) { cleanup(); return; }
373
+ if (typeof this.opts.onCreateFolder === 'function') {
374
+ const res = await this.opts.onCreateFolder(name);
375
+ if (res) { current.splice(0, 0, res); }
376
+ else { cleanup(); return; }
377
+ } else {
378
+ current.splice(0, 0, { name, children: [] });
379
+ }
380
+ this._creatingFolder = false;
381
+ this.render();
382
+ };
383
+
384
+ const onKey = (e) => {
385
+ if (e.key === 'Enter') {
386
+ e.preventDefault();
387
+ nameEl.blur();
388
+ } else if (e.key === 'Escape') {
389
+ e.preventDefault();
390
+ cleanup();
391
+ }
392
+ };
393
+
394
+ nameEl.addEventListener('keydown', onKey);
395
+ nameEl.addEventListener('blur', () => {
396
+ // commit on blur (allow Enter's blur to fire first)
397
+ setTimeout(() => {
398
+ if (!this._creatingFolder) return;
399
+ commit();
400
+ }, 0);
401
+ }, { once: true });
402
+ }
403
+
404
+ async handleUpload() {
405
+ if (typeof this.opts.onUpload !== 'function') return;
406
+ this._fileInput.value = '';
407
+ this._fileInput.multiple = true;
408
+ this._fileInput.onchange = async () => {
409
+ const files = Array.from(this._fileInput.files || []);
410
+ if (files.length === 0) return;
411
+ try {
412
+ const res = await this.opts.onUpload(files);
413
+ if (res) {
414
+ const current = this.currentFiles();
415
+ if (Array.isArray(res)) current.push(...res); else current.push(res);
416
+ this.render();
417
+ }
418
+ } catch (err) { console.error('onUpload error', err); }
419
+ };
420
+ this._fileInput.click();
421
+ }
422
+
423
+ async handleDropFiles(files) {
424
+ if (!files || files.length === 0) return;
425
+ if (typeof this.opts.onUpload !== 'function') return;
426
+ try {
427
+ const res = await this.opts.onUpload(files);
428
+ if (res) {
429
+ const current = this.currentFiles();
430
+ if (Array.isArray(res)) current.push(...res); else current.push(res);
431
+ this.render();
432
+ }
433
+ } catch (err) { console.error('onUpload error', err); }
434
+ }
435
+
436
+ select(i) {
437
+ const activeList = this.currentFiles();
438
+ if (this.multi) {
439
+ if (this.selectedIndices.has(i)) {
440
+ this.selectedIndices.delete(i);
441
+ }
442
+ else {
443
+ this.selectedIndices.add(i);
444
+ }
445
+ } else {
446
+ if (this.selectedIndices.has(i)) {
447
+ this.selectedIndices.clear();
448
+ }
449
+ else {
450
+ this.selectedIndices.clear();
451
+ this.selectedIndices.add(i);
452
+ }
453
+ }
454
+ this.updateSelectionUI();
455
+ if (typeof this.opts.onSelect === 'function') {
456
+ const indices = Array.from(this.selectedIndices).sort((a, b) => a - b);
457
+ const items = indices.map(idx => activeList[idx]);
458
+ this.opts.onSelect(items, indices);
459
+ }
460
+ }
461
+
462
+ enterFolder(i) {
463
+ const f = this.currentFiles()[i];
464
+ if (!f || !Array.isArray(f.children)) return;
465
+ this.stack.push({ name: f.name || 'Folder', files: f.children });
466
+ this.selectedIndices.clear();
467
+ this.render();
468
+ }
469
+
470
+ goToCrumb(idx) {
471
+ this.stack = this.stack.slice(0, idx + 1);
472
+ this.selectedIndices.clear();
473
+ this.render();
474
+ }
475
+ }
package/src/style.less ADDED
@@ -0,0 +1,124 @@
1
+ .browsejs {
2
+ --gap: 12px;
3
+ --selection-color: #2348d6;
4
+ display: grid;
5
+ grid-template-columns: 1fr 280px;
6
+ grid-template-rows: auto 1fr;
7
+ grid-template-areas: "breadcrumb breadcrumb" "gallery details";
8
+ gap: var(--gap);
9
+
10
+ button {
11
+ font-family: inherit;
12
+ }
13
+
14
+ .card {
15
+ background: transparent;
16
+ border: none;
17
+ overflow: hidden;
18
+ cursor: pointer;
19
+ display: flex;
20
+ flex-direction: column;
21
+ align-items: stretch;
22
+
23
+ img {
24
+ width: 100%;
25
+ height: 160px;
26
+ object-fit: contain;
27
+ display: block;
28
+ }
29
+ .meta {
30
+ padding: 3px;
31
+ font-size: 13px;
32
+ color: #0b1220;
33
+ white-space: nowrap;
34
+ overflow: hidden;
35
+ text-overflow: ellipsis;
36
+ }
37
+
38
+ .editable-name {
39
+ padding: 3px;
40
+ }
41
+
42
+ &.selected {
43
+ border-color: var(--selection-color);
44
+ box-shadow: 0 6px 18px #2463ff1f;
45
+ }
46
+ }
47
+
48
+ .gallery-grid {
49
+ box-sizing: border-box;
50
+ border: 2px dotted transparent;
51
+ grid-area: gallery;
52
+ display: grid;
53
+ grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
54
+ grid-auto-rows: max-content;
55
+ gap: var(--gap);
56
+ padding: var(--gap);
57
+ overflow-y: auto;
58
+ }
59
+
60
+ .details {
61
+ background: #fff;
62
+ border-radius: 8px;
63
+ padding: var(--gap);
64
+ min-height: 140px;
65
+ grid-area: details;
66
+ }
67
+
68
+ .preview {
69
+ width: 100%;
70
+ height: 180px;
71
+ object-fit: contain;
72
+ background: #e9eefc;
73
+ border-radius: 6px;
74
+ display: block;
75
+ margin-bottom: 10px;
76
+ }
77
+
78
+ .small {
79
+ font-size: 13px;
80
+ color: #475569;
81
+ }
82
+
83
+ .breadcrumb {
84
+ display: flex;
85
+ gap: 8px;
86
+ align-items: center;
87
+ justify-content: space-between;
88
+ margin-top: 8px;
89
+ grid-area: breadcrumb;
90
+
91
+ .crumb {
92
+ background: transparent;
93
+ border: 0;
94
+ padding: 4px 6px;
95
+ cursor: pointer;
96
+ color: var(--selection-color);
97
+
98
+ &:hover {
99
+ background: #2463ff0f;
100
+ }
101
+ }
102
+ .sep {
103
+ color: #94a3b8;
104
+ }
105
+ }
106
+
107
+ &.dragover .gallery-grid {
108
+ border-color: var(--selection-color);
109
+ .card {
110
+ opacity: 0.7;
111
+ }
112
+ }
113
+
114
+ @media (max-width: 800px) {
115
+ padding: 0 10px;
116
+ grid-template-columns: 1fr;
117
+ grid-template-rows: auto 1fr max-content;
118
+ grid-template-areas: "breadcrumb" "gallery" "details";
119
+
120
+ .details {
121
+ min-height: initial;
122
+ }
123
+ }
124
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "include": ["src/**/*"],
3
+ "compilerOptions": {
4
+ "allowJs": true,
5
+ "declaration": true,
6
+ "emitDeclarationOnly": true,
7
+ "outDir": "dist"
8
+ }
9
+ }