anentrypoint-design 0.0.28 → 0.0.30
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/README.md +42 -1
- package/dist/247420.app.js +3 -4
- package/dist/247420.css +332 -2
- package/dist/247420.js +37 -132
- package/package.json +3 -2
- package/src/bootstrap.js +38 -0
- package/src/components/chat.js +199 -0
- package/src/components/content.js +171 -0
- package/src/components/files-modals.js +105 -0
- package/src/components/files.js +126 -0
- package/src/components/shell.js +113 -0
- package/src/components.js +31 -523
- package/src/debug.js +34 -0
- package/src/highlight.js +60 -0
- package/src/index.js +22 -5
- package/src/markdown.js +61 -0
- package/src/web-components/ds-chat.js +75 -0
package/src/debug.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const registry = new Map();
|
|
2
|
+
|
|
3
|
+
export function register(name, snapshot) {
|
|
4
|
+
if (typeof name !== 'string' || !name) throw new Error('debug.register: name required');
|
|
5
|
+
if (typeof snapshot !== 'function') throw new Error('debug.register: snapshot fn required');
|
|
6
|
+
registry.set(name, snapshot);
|
|
7
|
+
expose();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function unregister(name) { registry.delete(name); expose(); }
|
|
11
|
+
|
|
12
|
+
export function list() { return [...registry.keys()]; }
|
|
13
|
+
|
|
14
|
+
export function snapshot(name) {
|
|
15
|
+
const fn = registry.get(name);
|
|
16
|
+
if (!fn) return null;
|
|
17
|
+
try { return fn(); } catch (e) { return { error: String(e && e.message || e) }; }
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function snapshotAll() {
|
|
21
|
+
const out = {};
|
|
22
|
+
for (const [k, fn] of registry) {
|
|
23
|
+
try { out[k] = fn(); } catch (e) { out[k] = { error: String(e && e.message || e) }; }
|
|
24
|
+
}
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function expose() {
|
|
29
|
+
if (typeof window === 'undefined') return;
|
|
30
|
+
const api = { list, snapshot, snapshotAll, register, unregister };
|
|
31
|
+
Object.defineProperty(window, '__debug', { value: api, configurable: true, writable: false });
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
expose();
|
package/src/highlight.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { register } from './debug.js';
|
|
2
|
+
|
|
3
|
+
const PRISM_BASE = 'https://cdn.jsdelivr.net/npm/prismjs@1.30.0';
|
|
4
|
+
const LANGS = ['markup', 'css', 'clike', 'javascript', 'jsx', 'tsx', 'typescript', 'json', 'bash', 'python'];
|
|
5
|
+
let _prism = null;
|
|
6
|
+
let _stats = { highlights: 0, errors: 0 };
|
|
7
|
+
|
|
8
|
+
function injectScript(src) {
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
const s = document.createElement('script');
|
|
11
|
+
s.src = src; s.async = false;
|
|
12
|
+
s.onload = () => resolve();
|
|
13
|
+
s.onerror = () => reject(new Error('script failed: ' + src));
|
|
14
|
+
document.head.appendChild(s);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let _loadPromise = null;
|
|
19
|
+
export function ensurePrism() {
|
|
20
|
+
if (_prism) return Promise.resolve(_prism);
|
|
21
|
+
if (_loadPromise) return _loadPromise;
|
|
22
|
+
_loadPromise = (async () => {
|
|
23
|
+
if (!window.Prism) {
|
|
24
|
+
window.Prism = window.Prism || { manual: true, disableWorkerMessageHandler: true };
|
|
25
|
+
await injectScript(PRISM_BASE + '/prism.min.js');
|
|
26
|
+
}
|
|
27
|
+
for (const lang of LANGS) {
|
|
28
|
+
const has = window.Prism && window.Prism.languages && window.Prism.languages[lang];
|
|
29
|
+
if (has) continue;
|
|
30
|
+
try { await injectScript(`${PRISM_BASE}/components/prism-${lang}.min.js`); }
|
|
31
|
+
catch { _stats.errors += 1; }
|
|
32
|
+
}
|
|
33
|
+
_prism = window.Prism;
|
|
34
|
+
return _prism;
|
|
35
|
+
})();
|
|
36
|
+
return _loadPromise;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export async function highlightElement(el) {
|
|
40
|
+
const prism = await ensurePrism();
|
|
41
|
+
if (!el) return;
|
|
42
|
+
prism.highlightElement(el);
|
|
43
|
+
_stats.highlights += 1;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export async function highlightAllUnder(root) {
|
|
47
|
+
const prism = await ensurePrism();
|
|
48
|
+
const els = (root || document).querySelectorAll('pre code[class*="lang-"], pre code[class*="language-"]');
|
|
49
|
+
els.forEach((el) => {
|
|
50
|
+
const cls = el.className;
|
|
51
|
+
if (/lang-(\w+)/.test(cls) && !/language-/.test(cls)) {
|
|
52
|
+
const m = cls.match(/lang-(\w+)/);
|
|
53
|
+
if (m) el.classList.add('language-' + m[1]);
|
|
54
|
+
}
|
|
55
|
+
prism.highlightElement(el);
|
|
56
|
+
_stats.highlights += 1;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
register('highlight', () => ({ loaded: !!_prism, langs: _prism ? Object.keys(_prism.languages || {}) : [], ...(_stats) }));
|
package/src/index.js
CHANGED
|
@@ -3,6 +3,11 @@ import { loadCss, scope } from './styles.js';
|
|
|
3
3
|
import { registerDeckStage, getDeckStage } from './deck-stage.js';
|
|
4
4
|
import * as components from './components.js';
|
|
5
5
|
import * as motion from './motion.js';
|
|
6
|
+
import * as debug from './debug.js';
|
|
7
|
+
import { renderMarkdown, ensureReady as ensureMarkdownReady } from './markdown.js';
|
|
8
|
+
import { ensurePrism, highlightAllUnder } from './highlight.js';
|
|
9
|
+
import { mountKit } from './bootstrap.js';
|
|
10
|
+
import { registerChatElement } from './web-components/ds-chat.js';
|
|
6
11
|
|
|
7
12
|
let _installed = false;
|
|
8
13
|
export async function installStyles(target) {
|
|
@@ -23,15 +28,27 @@ export function mount(rootEl, viewFn, { autoScope = true } = {}) {
|
|
|
23
28
|
}
|
|
24
29
|
const render = () => {
|
|
25
30
|
webjsx.applyDiff(rootEl, viewFn(render));
|
|
26
|
-
requestAnimationFrame(() =>
|
|
27
|
-
motion.animateTree(rootEl);
|
|
28
|
-
});
|
|
31
|
+
requestAnimationFrame(() => motion.animateTree(rootEl));
|
|
29
32
|
};
|
|
30
33
|
render();
|
|
31
34
|
return render;
|
|
32
35
|
}
|
|
33
36
|
|
|
34
|
-
|
|
37
|
+
if (typeof window !== 'undefined' && typeof customElements !== 'undefined') {
|
|
38
|
+
registerChatElement();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export {
|
|
42
|
+
webjsx, loadCss, scope, registerDeckStage, getDeckStage,
|
|
43
|
+
components, motion, debug, mountKit,
|
|
44
|
+
renderMarkdown, ensureMarkdownReady,
|
|
45
|
+
ensurePrism, highlightAllUnder,
|
|
46
|
+
registerChatElement
|
|
47
|
+
};
|
|
35
48
|
export const h = webjsx.createElement;
|
|
36
49
|
export const applyDiff = webjsx.applyDiff;
|
|
37
|
-
export default {
|
|
50
|
+
export default {
|
|
51
|
+
webjsx, loadCss, scope, installStyles, mount, h, applyDiff,
|
|
52
|
+
registerDeckStage, getDeckStage, components, motion, debug, mountKit,
|
|
53
|
+
renderMarkdown, ensurePrism, registerChatElement
|
|
54
|
+
};
|
package/src/markdown.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { register } from './debug.js';
|
|
2
|
+
|
|
3
|
+
let _marked = null;
|
|
4
|
+
let _purify = null;
|
|
5
|
+
let _stats = { renders: 0, sanitizedTags: 0 };
|
|
6
|
+
|
|
7
|
+
async function loadMarked() {
|
|
8
|
+
if (_marked) return _marked;
|
|
9
|
+
const mod = await import('https://cdn.jsdelivr.net/npm/marked@15.0.7/lib/marked.esm.js');
|
|
10
|
+
_marked = mod.marked;
|
|
11
|
+
_marked.setOptions({ breaks: true, gfm: true });
|
|
12
|
+
return _marked;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async function loadPurify() {
|
|
16
|
+
if (_purify) return _purify;
|
|
17
|
+
const mod = await import('https://cdn.jsdelivr.net/npm/dompurify@3.4.1/+esm');
|
|
18
|
+
_purify = mod.default || mod;
|
|
19
|
+
if (!_purify.sanitize) throw new Error('dompurify did not load a sanitize fn');
|
|
20
|
+
_purify.addHook('uponSanitizeElement', (node, data) => {
|
|
21
|
+
if (data.tagName && data.allowedTags && !data.allowedTags[data.tagName]) _stats.sanitizedTags += 1;
|
|
22
|
+
});
|
|
23
|
+
return _purify;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let _ready = null;
|
|
27
|
+
export function ensureReady() {
|
|
28
|
+
if (_ready) return _ready;
|
|
29
|
+
_ready = Promise.all([loadMarked(), loadPurify()]).then(() => true);
|
|
30
|
+
return _ready;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export async function renderMarkdown(text) {
|
|
34
|
+
const [marked, purify] = await Promise.all([loadMarked(), loadPurify()]);
|
|
35
|
+
const dirty = marked.parse(String(text || ''));
|
|
36
|
+
const clean = purify.sanitize(dirty, {
|
|
37
|
+
FORBID_TAGS: ['script', 'iframe', 'object', 'embed', 'form'],
|
|
38
|
+
FORBID_ATTR: ['onerror', 'onclick', 'onload', 'onmouseover'],
|
|
39
|
+
ADD_ATTR: ['target', 'rel']
|
|
40
|
+
});
|
|
41
|
+
_stats.renders += 1;
|
|
42
|
+
return clean;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function renderMarkdownSync(text) {
|
|
46
|
+
if (!_marked || !_purify) return null;
|
|
47
|
+
const dirty = _marked.parse(String(text || ''));
|
|
48
|
+
const clean = _purify.sanitize(dirty, {
|
|
49
|
+
FORBID_TAGS: ['script', 'iframe', 'object', 'embed', 'form'],
|
|
50
|
+
FORBID_ATTR: ['onerror', 'onclick', 'onload', 'onmouseover'],
|
|
51
|
+
ADD_ATTR: ['target', 'rel']
|
|
52
|
+
});
|
|
53
|
+
_stats.renders += 1;
|
|
54
|
+
return clean;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
register('markdown', () => ({
|
|
58
|
+
loaded: { marked: !!_marked, dompurify: !!_purify },
|
|
59
|
+
renders: _stats.renders,
|
|
60
|
+
sanitizedTags: _stats.sanitizedTags
|
|
61
|
+
}));
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import * as webjsx from '../../vendor/webjsx/index.js';
|
|
2
|
+
import { Chat, ChatComposer } from '../components/chat.js';
|
|
3
|
+
import { register } from '../debug.js';
|
|
4
|
+
|
|
5
|
+
let _stats = { mounts: 0, sends: 0 };
|
|
6
|
+
|
|
7
|
+
class DsChat extends HTMLElement {
|
|
8
|
+
static get observedAttributes() { return ['title', 'sub', 'placeholder']; }
|
|
9
|
+
|
|
10
|
+
constructor() {
|
|
11
|
+
super();
|
|
12
|
+
this._messages = [];
|
|
13
|
+
this._draft = '';
|
|
14
|
+
this._title = 'chat';
|
|
15
|
+
this._sub = '';
|
|
16
|
+
this._placeholder = 'message…';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
set messages(v) { this._messages = Array.isArray(v) ? v : []; this._render(); }
|
|
20
|
+
get messages() { return this._messages; }
|
|
21
|
+
|
|
22
|
+
connectedCallback() {
|
|
23
|
+
if (this.hasAttribute('messages')) {
|
|
24
|
+
try { this._messages = JSON.parse(this.getAttribute('messages')); } catch {}
|
|
25
|
+
}
|
|
26
|
+
this._title = this.getAttribute('title') || this._title;
|
|
27
|
+
this._sub = this.getAttribute('sub') || '';
|
|
28
|
+
this._placeholder = this.getAttribute('placeholder') || this._placeholder;
|
|
29
|
+
_stats.mounts += 1;
|
|
30
|
+
this._render();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
attributeChangedCallback(name, _old, val) {
|
|
34
|
+
if (name === 'title') this._title = val || 'chat';
|
|
35
|
+
if (name === 'sub') this._sub = val || '';
|
|
36
|
+
if (name === 'placeholder') this._placeholder = val || 'message…';
|
|
37
|
+
this._render();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
pushMessage(msg) {
|
|
41
|
+
this._messages = [...this._messages, msg];
|
|
42
|
+
this._render();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
_render() {
|
|
46
|
+
const onSend = (text) => {
|
|
47
|
+
_stats.sends += 1;
|
|
48
|
+
this.dispatchEvent(new CustomEvent('send', { detail: { text }, bubbles: true, composed: true }));
|
|
49
|
+
};
|
|
50
|
+
const onInput = (v) => { this._draft = v; this._render(); };
|
|
51
|
+
const view = Chat({
|
|
52
|
+
title: this._title,
|
|
53
|
+
sub: this._sub,
|
|
54
|
+
messages: this._messages,
|
|
55
|
+
composer: ChatComposer({
|
|
56
|
+
value: this._draft,
|
|
57
|
+
placeholder: this._placeholder,
|
|
58
|
+
onInput,
|
|
59
|
+
onSend
|
|
60
|
+
})
|
|
61
|
+
});
|
|
62
|
+
webjsx.applyDiff(this, view);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
let _registered = false;
|
|
67
|
+
export function registerChatElement() {
|
|
68
|
+
if (_registered) return;
|
|
69
|
+
if (!customElements.get('ds-chat')) customElements.define('ds-chat', DsChat);
|
|
70
|
+
_registered = true;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
register('ds-chat', () => ({ registered: _registered, ..._stats, instances: document.querySelectorAll('ds-chat').length }));
|
|
74
|
+
|
|
75
|
+
export { DsChat };
|