@ngockhoale/ckit 0.2.6 → 0.2.8
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/dist/src/adapters/launch/executor.d.ts +2 -0
- package/dist/src/adapters/launch/executor.js +12 -1
- package/dist/src/gui/server.js +1 -1
- package/dist/src/team/config.js +4 -2
- package/dist/src/team/engine.d.ts +10 -0
- package/dist/src/team/engine.js +118 -10
- package/dist/src/team/journal.d.ts +2 -0
- package/dist/src/team/journal.js +28 -3
- package/dist/src/team/runners.d.ts +4 -0
- package/dist/src/team/runners.js +16 -2
- package/dist/src/team/types.d.ts +6 -0
- package/dist/src/tui/team/model.js +2 -0
- package/gui/app.css +178 -18
- package/gui/app.js +318 -115
- package/gui/assets/ckit-oriental-avatar-pack/README.md +5 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-architect-01.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-architect-02.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-architect-03.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-architect-04.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-architect-05.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-architect-06.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-architect-07.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-architect-08.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-architect-09.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-data-ai-01.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-data-ai-02.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-data-ai-03.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-data-ai-04.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-data-ai-05.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-data-ai-06.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-data-ai-07.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-data-ai-08.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-data-ai-09.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-developer-01.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-developer-02.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-developer-03.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-developer-04.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-developer-05.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-developer-06.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-developer-07.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-developer-08.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-developer-09.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-devops-01.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-devops-02.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-devops-03.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-devops-04.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-devops-05.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-devops-06.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-devops-07.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-devops-08.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-devops-09.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-pm-01.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-pm-02.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-pm-03.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-pm-04.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-pm-05.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-pm-06.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-pm-07.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-pm-08.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-pm-09.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-qa-01.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-qa-02.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-qa-03.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-qa-04.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-qa-05.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-qa-06.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-qa-07.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-qa-08.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-qa-09.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-security-01.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-security-02.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-security-03.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-security-04.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-security-05.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-security-06.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-security-07.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-security-08.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/avatars/oriental-security-09.png +0 -0
- package/gui/assets/ckit-oriental-avatar-pack/manifest.json +447 -0
- package/gui/comic/assets/backgrounds/command-center.svg +1 -0
- package/gui/comic/assets/backgrounds/developer-workshop.svg +1 -0
- package/gui/comic/assets/backgrounds/handoff-corridor.svg +1 -0
- package/gui/comic/assets/backgrounds/incident-room.svg +1 -0
- package/gui/comic/assets/backgrounds/mission-overview.svg +1 -0
- package/gui/comic/assets/backgrounds/quality-lab.svg +1 -0
- package/gui/comic/assets/backgrounds/reporting-hall.svg +1 -0
- package/gui/comic/assets/backgrounds/research-library.svg +1 -0
- package/gui/comic/assets/backgrounds/review-chamber.svg +1 -0
- package/gui/comic/assets/backgrounds/strategy-room.svg +1 -0
- package/gui/comic/assets/effects/check-burst.svg +1 -0
- package/gui/comic/assets/effects/focus-lines.svg +1 -0
- package/gui/comic/assets/effects/glow.svg +1 -0
- package/gui/comic/assets/effects/particles.svg +1 -0
- package/gui/comic/assets/effects/speed-lines.svg +1 -0
- package/gui/comic/assets/effects/warning-flash.svg +1 -0
- package/gui/comic/assets/frame/episode-banner.svg +1 -0
- package/gui/comic/assets/frame/panel-corner.svg +1 -0
- package/gui/comic/assets/props/approval-seal.svg +1 -0
- package/gui/comic/assets/props/bug-warning.svg +1 -0
- package/gui/comic/assets/props/capsule.svg +1 -0
- package/gui/comic/assets/props/checklist.svg +1 -0
- package/gui/comic/assets/props/code-display.svg +1 -0
- package/gui/comic/assets/props/document.svg +1 -0
- package/gui/comic/assets/props/files.svg +1 -0
- package/gui/comic/assets/props/folder.svg +1 -0
- package/gui/comic/assets/props/magnifier.svg +1 -0
- package/gui/comic/assets/props/package.svg +1 -0
- package/gui/comic/assets/props/rejection-mark.svg +1 -0
- package/gui/comic/assets/props/report.svg +1 -0
- package/gui/comic/assets/props/scroll.svg +1 -0
- package/gui/comic/assets/props/shield.svg +1 -0
- package/gui/comic/assets/props/tablet.svg +1 -0
- package/gui/comic/assets/props/workstation.svg +1 -0
- package/gui/comic/comic.css +130 -0
- package/gui/comic/contact-sheet.html +15 -0
- package/gui/comic/contact-sheet.js +41 -0
- package/gui/comic/engine.js +366 -0
- package/gui/comic/manifests/backgrounds.json +216 -0
- package/gui/comic/manifests/characters.json +96 -0
- package/gui/comic/manifests/effects.json +96 -0
- package/gui/comic/manifests/props.json +246 -0
- package/gui/comic/manifests/scenes.json +205 -0
- package/gui/comic/render.js +594 -0
- package/gui/index.html +30 -14
- package/gui/network.js +253 -254
- package/package.json +2 -1
|
@@ -0,0 +1,594 @@
|
|
|
1
|
+
/* CKit Living Comic Engine - DOM renderer, motion and reader controls. Classic script: window.CKComic.create(root, deps).
|
|
2
|
+
The comic has no authority: it only reads events, fetches the static manifests (GET) and never sends anything. */
|
|
3
|
+
(function () {
|
|
4
|
+
'use strict';
|
|
5
|
+
var MAX_PANELS = 120, CHUNK = 60, MAX_ANIM = 4, MAX_SHIMMER = 3, MAX_TEXT = 180, FLUSH_MS = 250, NEAR_PX = 80;
|
|
6
|
+
var NS = 'http://www.w3.org/2000/svg';
|
|
7
|
+
var TRUTH = {
|
|
8
|
+
planned: ['Dự kiến', '◌', '#8A9AAF'], working: ['Đang làm', '◔', '#F3A544'], reported: ['Đã báo cáo', '✎', '#21D6E8'],
|
|
9
|
+
confirmed: ['Đã quyết định', '✔', '#A36BFF'], verified: ['Đã xác minh', '✔', '#4AD69A'], failed: ['Có lỗi', '✖', '#F05668'],
|
|
10
|
+
blocked: ['Bị chặn', '⛔', '#F05668'], waiting: ['Chờ chủ dự án', '⏳', '#E0C341'], stopped: ['Đã dừng', '■', '#8A9AAF'], unknown: ['Chưa rõ', '?', '#8A9AAF']
|
|
11
|
+
};
|
|
12
|
+
var MOTION_KEY = 'ckit.comic.motion';
|
|
13
|
+
var manifestsP = null;
|
|
14
|
+
|
|
15
|
+
/* ---- safe urls: same-origin comic/ or assets/ paths only ---- */
|
|
16
|
+
function guiBase() { var p = location.pathname; return p.slice(0, p.lastIndexOf('/') + 1) || '/'; }
|
|
17
|
+
function safeSrc(u) {
|
|
18
|
+
if (typeof u !== 'string' || !u || u.length > 300 || /[\u0000-\u001f\\]/.test(u)) return '';
|
|
19
|
+
var url; try { url = new URL(u, location.href); } catch (e) { return ''; }
|
|
20
|
+
if (url.origin !== location.origin || url.search || url.hash) return '';
|
|
21
|
+
var E = window.CKComicEngine;
|
|
22
|
+
return E && E.safeAssetPath(url.pathname, guiBase()) ? u : '';
|
|
23
|
+
}
|
|
24
|
+
function comicSrc(s) { if (typeof s !== 'string') return ''; return safeSrc(/^comic\//.test(s) ? s : 'comic/' + s.replace(/^\//, '')); }
|
|
25
|
+
function loadManifests() {
|
|
26
|
+
if (manifestsP) return manifestsP;
|
|
27
|
+
var names = ['characters', 'backgrounds', 'props', 'effects', 'scenes'];
|
|
28
|
+
manifestsP = Promise.all(names.map(function (n) {
|
|
29
|
+
return fetch('comic/manifests/' + n + '.json', {method: 'GET', credentials: 'same-origin'}).then(function (r) { return r.ok ? r.json() : null; }).catch(function () { return null; });
|
|
30
|
+
})).then(function (all) {
|
|
31
|
+
var m = {};
|
|
32
|
+
names.forEach(function (n, i) {
|
|
33
|
+
var map = {}, items = all[i] && Array.isArray(all[i].items) ? all[i].items : [];
|
|
34
|
+
items.forEach(function (it) { if (it && typeof it.id === 'string') map[it.id] = it; });
|
|
35
|
+
m[n] = map; m[n + 'List'] = items;
|
|
36
|
+
});
|
|
37
|
+
return m;
|
|
38
|
+
});
|
|
39
|
+
return manifestsP;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/* ---- tiny dom helpers ---- */
|
|
43
|
+
function el(tag, cls, text, attrs) {
|
|
44
|
+
var e = document.createElement(tag);
|
|
45
|
+
if (cls) e.className = cls;
|
|
46
|
+
if (text != null) e.textContent = text;
|
|
47
|
+
if (attrs) for (var k in attrs) e.setAttribute(k, attrs[k]);
|
|
48
|
+
return e;
|
|
49
|
+
}
|
|
50
|
+
function sv(tag, attrs, parent) {
|
|
51
|
+
var e = document.createElementNS(NS, tag);
|
|
52
|
+
for (var k in attrs) e.setAttribute(k, attrs[k]);
|
|
53
|
+
if (parent) parent.appendChild(e);
|
|
54
|
+
return e;
|
|
55
|
+
}
|
|
56
|
+
function pad2(n) { return n < 10 ? '0' + n : String(n); }
|
|
57
|
+
function clipText(s) { s = String(s == null ? '' : s); return s.length > MAX_TEXT ? s.slice(0, MAX_TEXT - 1).trimEnd() + '…' : s; }
|
|
58
|
+
function hexA(hex, a) {
|
|
59
|
+
var m = /^#([0-9a-f]{6})$/i.exec(hex || ''); if (!m) return 'rgba(138,154,175,' + a + ')';
|
|
60
|
+
var n = parseInt(m[1], 16); return 'rgba(' + (n >> 16) + ',' + (n >> 8 & 255) + ',' + (n & 255) + ',' + a + ')';
|
|
61
|
+
}
|
|
62
|
+
function img(src, cls, alt) {
|
|
63
|
+
var i = el('img', cls); i.setAttribute('alt', alt || ''); i.setAttribute('aria-hidden', alt ? 'false' : 'true');
|
|
64
|
+
i.loading = 'lazy'; i.decoding = 'async'; i.draggable = false; i.src = src; return i;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/* ---- bubble shapes (SVG sized to the measured text box) ---- */
|
|
68
|
+
var TAIL = 17;
|
|
69
|
+
function speechPath(w, h, tx, dir) {
|
|
70
|
+
var r = Math.min(h * 0.42, 34), x0 = 1.5, y0 = 1.5, x1 = w - 1.5, y1 = h - 1.5;
|
|
71
|
+
tx = Math.max(x0 + r + 14, Math.min(x1 - r - 14, tx));
|
|
72
|
+
var tip = tx + dir * 9;
|
|
73
|
+
return 'M' + (x0 + r) + ',' + y0 + 'H' + (x1 - r) + 'Q' + x1 + ',' + y0 + ' ' + x1 + ',' + (y0 + r) + 'V' + (y1 - r) + 'Q' + x1 + ',' + y1 + ' ' + (x1 - r) + ',' + y1 +
|
|
74
|
+
'H' + (tx + 11) + 'L' + tip + ',' + (h + TAIL - 2) + 'L' + (tx - 11) + ',' + y1 + 'H' + (x0 + r) + 'Q' + x0 + ',' + y1 + ' ' + x0 + ',' + (y1 - r) + 'V' + (y0 + r) + 'Q' + x0 + ',' + y0 + ' ' + (x0 + r) + ',' + y0 + 'Z';
|
|
75
|
+
}
|
|
76
|
+
function jaggedPoints(w, h) {
|
|
77
|
+
var pts = [], s = 15, sp = 6, x, y, n;
|
|
78
|
+
n = Math.max(2, Math.round(w / s)); for (x = 0; x < n; x++) { pts.push([x * w / n, 0]); pts.push([(x + .5) * w / n, -sp]); }
|
|
79
|
+
n = Math.max(2, Math.round(h / s)); for (y = 0; y < n; y++) { pts.push([w, y * h / n]); pts.push([w + sp, (y + .5) * h / n]); }
|
|
80
|
+
n = Math.max(2, Math.round(w / s)); for (x = 0; x < n; x++) { pts.push([w - x * w / n, h]); pts.push([w - (x + .5) * w / n, h + sp]); }
|
|
81
|
+
n = Math.max(2, Math.round(h / s)); for (y = 0; y < n; y++) { pts.push([0, h - y * h / n]); pts.push([-sp, h - (y + .5) * h / n]); }
|
|
82
|
+
return pts.map(function (p) { return p[0].toFixed(1) + ',' + p[1].toFixed(1); }).join(' ');
|
|
83
|
+
}
|
|
84
|
+
function drawBubble(svg, kind, w, h, tx, dir, col) {
|
|
85
|
+
while (svg.firstChild) svg.removeChild(svg.firstChild);
|
|
86
|
+
var th = kind === 'thought' ? 24 : TAIL, W = Math.ceil(w), H = Math.ceil(h);
|
|
87
|
+
svg.setAttribute('width', W); svg.setAttribute('height', H + th); svg.setAttribute('viewBox', '0 0 ' + W + ' ' + (H + th));
|
|
88
|
+
var fill = kind === 'warning' ? '#fff3ea' : kind === 'thought' ? '#f1f5ff' : '#fffaf0', ink = '#0b1020';
|
|
89
|
+
if (kind === 'thought') {
|
|
90
|
+
var g = sv('g', {fill: fill, stroke: ink, 'stroke-width': 2.5}, svg), rr = 9, x, y, step = 18;
|
|
91
|
+
for (x = rr + 4; x < W - rr; x += step) { sv('circle', {cx: x, cy: 4, r: rr}, g); sv('circle', {cx: x, cy: H - 4, r: rr}, g); }
|
|
92
|
+
for (y = rr + 4; y < H - rr; y += step) { sv('circle', {cx: 4, cy: y, r: rr}, g); sv('circle', {cx: W - 4, cy: y, r: rr}, g); }
|
|
93
|
+
var cx = Math.max(24, Math.min(W - 24, tx));
|
|
94
|
+
sv('circle', {cx: cx, cy: H + 4, r: 6}, g); sv('circle', {cx: cx + dir * 8, cy: H + 13, r: 4.2}, g); sv('circle', {cx: cx + dir * 13, cy: H + 20, r: 2.8}, g);
|
|
95
|
+
sv('rect', {x: 4, y: 4, width: W - 8, height: H - 8, rx: 14, fill: fill, stroke: 'none'}, svg);
|
|
96
|
+
} else if (kind === 'warning') {
|
|
97
|
+
var t2 = Math.max(18, Math.min(W - 18, tx));
|
|
98
|
+
sv('path', {d: 'M' + (t2 - 11) + ',' + (H - 4) + 'L' + (t2 + dir * 9) + ',' + (H + th) + 'L' + (t2 + 11) + ',' + (H - 4) + 'Z', fill: fill, stroke: '#e5461f', 'stroke-width': 3, 'stroke-linejoin': 'round'}, svg);
|
|
99
|
+
sv('polygon', {points: jaggedPoints(W, H), fill: fill, stroke: '#e5461f', 'stroke-width': 3, 'stroke-linejoin': 'round', transform: 'translate(0,0)'}, svg);
|
|
100
|
+
} else {
|
|
101
|
+
sv('path', {d: speechPath(W, H, tx, dir), fill: fill, stroke: kind === 'question' ? '#1ec8dc' : ink, 'stroke-width': kind === 'question' ? 3.2 : 2.6, 'stroke-linejoin': 'round'}, svg);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function ownerSilhouette() {
|
|
106
|
+
var s = sv('svg', {viewBox: '0 0 64 64', class: 'ck-owner-svg', 'aria-hidden': 'true'});
|
|
107
|
+
sv('circle', {cx: 32, cy: 22, r: 11, fill: 'currentColor'}, s);
|
|
108
|
+
sv('path', {d: 'M10 58c1-14 10-22 22-22s21 8 22 22z', fill: 'currentColor'}, s);
|
|
109
|
+
return s;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/* ================= create ================= */
|
|
113
|
+
function create(root, deps) {
|
|
114
|
+
deps = deps || {};
|
|
115
|
+
var Eng = window.CKComicEngine;
|
|
116
|
+
var story = Eng.createStory({agents: {}, teams: {}, directorId: ''});
|
|
117
|
+
var M = null, destroyed = false;
|
|
118
|
+
var timers = {}, tid = 0, rafs = {}, rid = 0, ros = [], anims = [], shimmering = [];
|
|
119
|
+
var els = {}, byId = {}; // beat index -> {panel, hdr, beat, sig, meta}
|
|
120
|
+
var lo = 0, hi = 0, cap = MAX_PANELS;
|
|
121
|
+
var pendingAdded = [], pendingUpdated = [], scheduled = false, lastFlush = 0;
|
|
122
|
+
var follow = true, unseen = 0, history = false, focusIdx = -1, playing = false, speed = 1, playTimer = 0, lastWidthClass = null;
|
|
123
|
+
var motion = 'full', parX = 0, parY = 0, parEl = null, parRaf = 0;
|
|
124
|
+
var lastEp = 0, renderedEp = {};
|
|
125
|
+
var openedFrom = null;
|
|
126
|
+
|
|
127
|
+
function later(fn, ms) { var id = ++tid; timers[id] = setTimeout(function () { delete timers[id]; if (!destroyed) fn(); }, ms); return id; }
|
|
128
|
+
function raf(fn) { var id = ++rid; rafs[id] = requestAnimationFrame(function () { delete rafs[id]; if (!destroyed) fn(); }); return id; }
|
|
129
|
+
function clearTimers() {
|
|
130
|
+
Object.keys(timers).forEach(function (k) { clearTimeout(timers[k]); }); timers = {};
|
|
131
|
+
Object.keys(rafs).forEach(function (k) { cancelAnimationFrame(rafs[k]); }); rafs = {};
|
|
132
|
+
if (playTimer) { clearInterval(playTimer); playTimer = 0; }
|
|
133
|
+
if (parRaf) { cancelAnimationFrame(parRaf); parRaf = 0; }
|
|
134
|
+
anims.forEach(function (a) { try { a.cancel(); } catch (e) { /* gone */ } }); anims = [];
|
|
135
|
+
var caps = root.querySelectorAll('.ck-capsule'); for (var i = 0; i < caps.length; i++) caps[i].remove();
|
|
136
|
+
}
|
|
137
|
+
function ro(target, fn) {
|
|
138
|
+
if (typeof ResizeObserver === 'undefined') { raf(fn); return null; }
|
|
139
|
+
var o = new ResizeObserver(function () { if (!destroyed) fn(); }); o.observe(target); ros.push(o); return o;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/* ---- chrome ---- */
|
|
143
|
+
root.classList.add('ck-root');
|
|
144
|
+
root.textContent = '';
|
|
145
|
+
var head = el('div', 'ck-head');
|
|
146
|
+
var brand = el('div', 'ck-brand'); brand.appendChild(el('span', 'ck-logo', 'CKit Comic')); var count = el('span', 'ck-count', ''); brand.appendChild(count);
|
|
147
|
+
var histBadge = el('span', 'ck-hist', 'Đang xem lại'); histBadge.hidden = true;
|
|
148
|
+
var replay = el('div', 'ck-replay'); replay.hidden = true;
|
|
149
|
+
var bPrev = el('button', 'ck-b', '⏮ cảnh trước', {type: 'button', 'aria-label': 'Cảnh trước'});
|
|
150
|
+
var bPlay = el('button', 'ck-b ck-play', '⏯ Phát lại', {type: 'button'});
|
|
151
|
+
var bNext = el('button', 'ck-b', 'cảnh sau ⏭', {type: 'button', 'aria-label': 'Cảnh sau'});
|
|
152
|
+
var speedBox = el('span', 'ck-speed'), speedBtns = [0.5, 1, 2].map(function (v) {
|
|
153
|
+
var b = el('button', 'ck-b ck-sp', v + 'x', {type: 'button', 'aria-pressed': v === 1 ? 'true' : 'false'}); b.onclick = function () { setSpeed(v); }; speedBox.appendChild(b); return b;
|
|
154
|
+
});
|
|
155
|
+
replay.appendChild(bPrev); replay.appendChild(bPlay); replay.appendChild(bNext); replay.appendChild(speedBox);
|
|
156
|
+
var tools = el('div', 'ck-tools');
|
|
157
|
+
var followLbl = el('label', 'ck-follow'), followCb = el('input', '', null, {type: 'checkbox'}); followCb.checked = true;
|
|
158
|
+
followLbl.appendChild(followCb); followLbl.appendChild(el('span', '', 'Theo dõi trực tiếp'));
|
|
159
|
+
var motionSel = el('select', 'ck-motion', null, {'aria-label': 'Chuyển động'});
|
|
160
|
+
[['full', 'Đầy đủ'], ['reduced', 'Giảm chuyển động'], ['static', 'Tĩnh']].forEach(function (o) { motionSel.appendChild(el('option', '', o[1], {value: o[0]})); });
|
|
161
|
+
tools.appendChild(followLbl); tools.appendChild(motionSel);
|
|
162
|
+
head.appendChild(brand); head.appendChild(histBadge); head.appendChild(replay); head.appendChild(tools);
|
|
163
|
+
var empty = el('div', 'ck-empty', 'Truyện tranh sẽ kể lại chuyến chạy theo thời gian thực: ai nói gì, mỗi lần bàn giao, mỗi phán quyết. Hãy bắt đầu một nhiệm vụ ở ô bên dưới hoặc mở Runs để xem lại.');
|
|
164
|
+
var more = el('button', 'ck-more', '', {type: 'button'}); more.hidden = true;
|
|
165
|
+
var grid = el('div', 'ck-grid', null, {role: 'list', 'aria-label': 'Truyện tranh của lần chạy'});
|
|
166
|
+
var newChip = el('button', 'ck-newchip', '', {type: 'button'}); newChip.hidden = true;
|
|
167
|
+
root.appendChild(head); root.appendChild(empty); root.appendChild(more); root.appendChild(grid); root.appendChild(newChip);
|
|
168
|
+
|
|
169
|
+
/* ---- motion ---- */
|
|
170
|
+
function setMotion(m, persist) {
|
|
171
|
+
if (m !== 'full' && m !== 'reduced' && m !== 'static') m = 'full';
|
|
172
|
+
motion = m; root.setAttribute('data-motion', m); motionSel.value = m;
|
|
173
|
+
if (persist) { try { localStorage.setItem(MOTION_KEY, m); } catch (e) { /* private mode */ } }
|
|
174
|
+
if (m !== 'full') { anims.forEach(function (a) { try { a.cancel(); } catch (e) { /* gone */ } }); anims = []; }
|
|
175
|
+
if (m === 'static') { shimmering.forEach(function (i) { if (els[i]) els[i].panel.classList.remove('is-working'); }); shimmering = []; } else syncShimmer();
|
|
176
|
+
}
|
|
177
|
+
(function initMotion() {
|
|
178
|
+
var saved = null; try { saved = localStorage.getItem(MOTION_KEY); } catch (e) { /* ignore */ }
|
|
179
|
+
var rm = window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
180
|
+
setMotion(saved === 'full' || saved === 'reduced' || saved === 'static' ? saved : rm ? 'reduced' : 'full', false);
|
|
181
|
+
})();
|
|
182
|
+
motionSel.onchange = function () { setMotion(motionSel.value, true); };
|
|
183
|
+
|
|
184
|
+
function syncShimmer() {
|
|
185
|
+
shimmering = shimmering.filter(function (i) { var x = els[i]; if (x && x.beat.open && x.beat.truth === 'working') return true; if (x) x.panel.classList.remove('is-working'); return false; });
|
|
186
|
+
if (motion === 'static') return;
|
|
187
|
+
for (var i = hi - 1; i >= lo && shimmering.length < MAX_SHIMMER; i--) {
|
|
188
|
+
var x = els[i]; if (x && x.beat.open && x.beat.truth === 'working' && shimmering.indexOf(i) < 0) { shimmering.push(i); x.panel.classList.add('is-working'); }
|
|
189
|
+
}
|
|
190
|
+
// keep only the newest open beats animated
|
|
191
|
+
while (shimmering.length > MAX_SHIMMER) { var old = shimmering.shift(); if (els[old]) els[old].panel.classList.remove('is-working'); }
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/* ---- character resolution ---- */
|
|
195
|
+
function avatarIdOf(url) { var m = /\/([a-z0-9-]+)\.png$/.exec(url || ''); return m ? m[1] : ''; }
|
|
196
|
+
function infoOf(id) { var i = null; try { i = deps.agentInfo && deps.agentInfo(id); } catch (e) { i = null; } return i || {name: String(id), short: String(id).slice(0, 2).toUpperCase(), team: 'director', color: '#8A9AAF'}; }
|
|
197
|
+
function spriteFor(avatarUrl, pose) {
|
|
198
|
+
if (!M || !avatarUrl) return '';
|
|
199
|
+
var aid = avatarIdOf(avatarUrl); if (!aid) return '';
|
|
200
|
+
var list = M.charactersList || [];
|
|
201
|
+
for (var i = 0; i < list.length; i++) {
|
|
202
|
+
var c = list[i]; if (c && c.avatarId === aid && c.poses) { var s = c.poses[pose] || c.poses.idle || c.poses[Object.keys(c.poses)[0]]; var ok = s ? comicSrc(s) : ''; if (ok) return ok; }
|
|
203
|
+
}
|
|
204
|
+
return '';
|
|
205
|
+
}
|
|
206
|
+
function buildChar(c, beat, color) {
|
|
207
|
+
var fig = el('div', 'ck-char side-' + (c.side || 'center') + (c.speaking ? ' is-speaking' : ''));
|
|
208
|
+
fig.setAttribute('data-pose', c.pose || 'idle');
|
|
209
|
+
var frame = el('div', 'ck-bust'), name, sub = '';
|
|
210
|
+
if (c.agentId === 'owner') {
|
|
211
|
+
fig.classList.add('is-owner'); frame.appendChild(ownerSilhouette()); name = 'Chủ dự án'; sub = 'Owner';
|
|
212
|
+
} else if (!c.agentId && c.teamId) {
|
|
213
|
+
var tn = deps.teamName ? deps.teamName(c.teamId) : String(c.teamId);
|
|
214
|
+
fig.classList.add('is-team'); name = tn; sub = 'Cả nhóm';
|
|
215
|
+
frame.appendChild(el('span', 'ck-mono', String(tn).replace(/^team\s+/i, '').slice(0, 2).toUpperCase()));
|
|
216
|
+
if (deps.teamColor) fig.style.setProperty('--cc', deps.teamColor(c.teamId));
|
|
217
|
+
} else {
|
|
218
|
+
var info = infoOf(c.agentId), url = '';
|
|
219
|
+
try { url = (deps.avatarUrl && deps.avatarUrl(c.agentId)) || ''; } catch (e) { url = ''; }
|
|
220
|
+
url = safeSrc(url);
|
|
221
|
+
name = info.name || String(c.agentId); sub = info.team && deps.teamName ? deps.teamName(info.team) : '';
|
|
222
|
+
var sprite = spriteFor(url, c.pose);
|
|
223
|
+
if (sprite) { frame.classList.add('is-sprite'); frame.appendChild(img(sprite, 'ck-art', name)); if (c.side === 'right') frame.classList.add('flip'); }
|
|
224
|
+
else if (url) frame.appendChild(img(url, 'ck-art ck-avatar', name));
|
|
225
|
+
else frame.appendChild(el('span', 'ck-mono', (info.short || name).slice(0, 2).toUpperCase()));
|
|
226
|
+
if (info.color) fig.style.setProperty('--cc', info.color);
|
|
227
|
+
}
|
|
228
|
+
var plate = el('div', 'ck-plate'); plate.appendChild(el('b', '', name)); if (sub) plate.appendChild(el('small', '', sub));
|
|
229
|
+
fig.appendChild(frame); fig.appendChild(plate);
|
|
230
|
+
return fig;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/* ---- bubbles ---- */
|
|
234
|
+
function sideOf(beat, speakerId) {
|
|
235
|
+
if (speakerId == null) return 'left';
|
|
236
|
+
for (var i = 0; i < beat.cast.length; i++) if (beat.cast[i].agentId === speakerId) return beat.cast[i].side || 'center';
|
|
237
|
+
return 'left';
|
|
238
|
+
}
|
|
239
|
+
function openInspector(beat, line, from) { openedFrom = from || null; if (deps.onOpenSource) { try { deps.onOpenSource(beat); } catch (e) { /* host handler */ } } showInspector(beat, line); }
|
|
240
|
+
function buildLine(beat, line, color) {
|
|
241
|
+
var kind = line.kind, text = clipText(line.text), truncated = String(line.text || '').length > MAX_TEXT;
|
|
242
|
+
var hasFull = !!line.full || truncated;
|
|
243
|
+
if (kind === 'narration') {
|
|
244
|
+
var isHo = beat.type === 'handoff';
|
|
245
|
+
var cap = el('div', isHo ? 'ck-banner' : 'ck-cap'); cap.appendChild(el('span', 'ck-captxt', text));
|
|
246
|
+
if (hasFull) cap.appendChild(srcBtn(beat, line));
|
|
247
|
+
return cap;
|
|
248
|
+
}
|
|
249
|
+
if (kind === 'status') { return el('div', 'ck-pill', text); }
|
|
250
|
+
var side = sideOf(beat, line.speakerId), dir = side === 'right' ? 1 : side === 'left' ? -1 : 0;
|
|
251
|
+
var wrap = el('div', 'ck-bub k-' + kind + ' side-' + side);
|
|
252
|
+
var svg = document.createElementNS(NS, 'svg'); svg.setAttribute('class', 'ck-bsvg'); svg.setAttribute('aria-hidden', 'true'); wrap.appendChild(svg);
|
|
253
|
+
var box = el('div', 'ck-btxt'); box.appendChild(el('span', 'ck-t', text));
|
|
254
|
+
if (kind === 'question') box.appendChild(el('span', 'ck-q', '?'));
|
|
255
|
+
if (kind === 'quote') box.appendChild(el('span', 'ck-trich', 'trích', {title: 'Trích dẫn từ lời của agent'}));
|
|
256
|
+
if (hasFull) box.appendChild(srcBtn(beat, line));
|
|
257
|
+
wrap.appendChild(box);
|
|
258
|
+
var kShape = kind === 'paraphrase' ? 'speech' : kind;
|
|
259
|
+
var redraw = function () {
|
|
260
|
+
var w = box.offsetWidth, h = box.offsetHeight; if (!w || !h) return;
|
|
261
|
+
var tx = side === 'right' ? w * 0.82 : side === 'left' ? w * 0.18 : w * 0.5;
|
|
262
|
+
drawBubble(svg, kShape, w, h, tx, dir || 1, color); wrap.classList.add('drawn');
|
|
263
|
+
};
|
|
264
|
+
ro(box, redraw); raf(redraw);
|
|
265
|
+
return wrap;
|
|
266
|
+
}
|
|
267
|
+
function srcBtn(beat, line) {
|
|
268
|
+
var b = el('button', 'ck-src', 'Xem nguyên văn', {type: 'button'});
|
|
269
|
+
b.onclick = function (ev) { ev.stopPropagation(); openInspector(beat, line, b); };
|
|
270
|
+
return b;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/* ---- panel ---- */
|
|
274
|
+
function lineSig(b) { return b.lines.map(function (l) { return l.kind + '|' + l.speakerId + '|' + l.text + '|' + (l.full ? 1 : 0); }).join('\n'); }
|
|
275
|
+
function castSig(b) { return b.cast.map(function (c) { return [c.agentId || c.teamId, c.side, c.pose, c.speaking ? 1 : 0].join(':'); }).join(','); }
|
|
276
|
+
function sceneSig(b) { return [b.scene, b.props.join(','), b.effect || '', b.team].join('|'); }
|
|
277
|
+
function chipSig(b) { return [b.truth, b.status, b.open ? 1 : 0, b.simulated ? 1 : 0].join('|'); }
|
|
278
|
+
|
|
279
|
+
function fillScene(x, beat, fresh) {
|
|
280
|
+
var sc = M && M.scenes && M.scenes[beat.scene] || null, L = x.layers, col = deps.teamColor ? deps.teamColor(beat.team) : '#8A9AAF';
|
|
281
|
+
L.bg.textContent = ''; L.props.textContent = ''; L.fx.textContent = '';
|
|
282
|
+
var light = sc && sc.light || col;
|
|
283
|
+
L.light.style.background = 'radial-gradient(ellipse at 50% 38%,' + hexA(light, .32) + ' 0,' + hexA(light, .08) + ' 52%,transparent 75%)';
|
|
284
|
+
if (sc && M.backgrounds) { var bg = M.backgrounds[sc.backgroundId], s = bg && comicSrc(bg.src); if (s) L.bg.appendChild(img(s, 'ck-bgimg')); }
|
|
285
|
+
var pids = beat.props && beat.props.length ? beat.props : sc && sc.defaultProps || [];
|
|
286
|
+
for (var i = 0; i < pids.length && i < 3; i++) {
|
|
287
|
+
var p = M && M.props && M.props[pids[i]], ps = p && comicSrc(p.src); if (!ps) continue;
|
|
288
|
+
var pi = img(ps, 'ck-prop slot' + i); L.props.appendChild(pi);
|
|
289
|
+
}
|
|
290
|
+
var fxId = beat.effect || (sc && sc.effect), fx = fxId && M && M.effects && M.effects[fxId], fs = fx && comicSrc(fx.src);
|
|
291
|
+
if (fs) { var fi = img(fs, 'ck-fxi fx-' + fxId); L.fx.appendChild(fi); }
|
|
292
|
+
}
|
|
293
|
+
function fillCast(x, beat) {
|
|
294
|
+
var L = x.layers, col = deps.teamColor ? deps.teamColor(beat.team) : '#8A9AAF';
|
|
295
|
+
var old = L.cast; // keep identity: avatars snapshot on first render only
|
|
296
|
+
var keep = x.snap || (x.snap = {});
|
|
297
|
+
L.cast.textContent = '';
|
|
298
|
+
var seen = {};
|
|
299
|
+
beat.cast.forEach(function (c) { if (seen[c.agentId + c.side]) return; seen[c.agentId + c.side] = 1; var f = buildChar(c, beat, col, keep); L.cast.appendChild(f); });
|
|
300
|
+
L.cast.setAttribute('data-n', String(beat.cast.length));
|
|
301
|
+
return old;
|
|
302
|
+
}
|
|
303
|
+
function fillLines(x, beat) {
|
|
304
|
+
var col = deps.teamColor ? deps.teamColor(beat.team) : '#8A9AAF';
|
|
305
|
+
x.layers.bubbles.textContent = '';
|
|
306
|
+
beat.lines.forEach(function (l) { x.layers.bubbles.appendChild(buildLine(beat, l, col)); });
|
|
307
|
+
}
|
|
308
|
+
function fillChip(x, beat) {
|
|
309
|
+
var t = TRUTH[beat.truth] || TRUTH.unknown, chip = x.layers.chip;
|
|
310
|
+
chip.textContent = ''; chip.style.setProperty('--sc', t[2]); chip.setAttribute('data-truth', beat.truth);
|
|
311
|
+
chip.appendChild(el('i', 'ck-ico', t[1]));
|
|
312
|
+
var lbl = (beat.truth === 'working' && !beat.open) ? 'Kết thúc lượt' : t[0]; var txt = el('span', 'ck-lbl', lbl); chip.appendChild(txt);
|
|
313
|
+
if (beat.simulated) chip.appendChild(el('span', 'ck-sim', 'MÔ PHỎNG'));
|
|
314
|
+
if (beat.status && beat.status !== t[0]) chip.appendChild(el('span', 'ck-st', beat.status));
|
|
315
|
+
if (beat.open && beat.truth === 'working') { var d = el('span', 'ck-dots'); d.appendChild(el('i')); d.appendChild(el('i')); d.appendChild(el('i')); chip.appendChild(d); }
|
|
316
|
+
chip.title = t[0] + (beat.status ? ' · ' + beat.status : '');
|
|
317
|
+
x.panel.setAttribute('data-truth', beat.truth);
|
|
318
|
+
}
|
|
319
|
+
function metaOf(beat) {
|
|
320
|
+
var a = {}; beat.cast.forEach(function (c) { if (c.agentId || c.teamId) a[c.agentId || c.teamId] = 1; });
|
|
321
|
+
return {agents: a, team: beat.team};
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function buildPanel(idx, beat, animate, stagger) {
|
|
325
|
+
var col = deps.teamColor ? deps.teamColor(beat.team) : '#8A9AAF';
|
|
326
|
+
var p = el('article', 'ck-panel w-' + beat.weight + ' t-' + beat.type, null, {role: 'listitem', tabindex: '0', 'aria-label': 'Cảnh ' + beat.seq + ': ' + beat.title});
|
|
327
|
+
p.setAttribute('data-seq', String(beat.seq)); p.setAttribute('data-beat', beat.id); p.setAttribute('data-team', beat.team);
|
|
328
|
+
p.style.setProperty('--pc', col); p.style.setProperty('--pg', hexA(col, .45));
|
|
329
|
+
var L = {};
|
|
330
|
+
L.base = el('div', 'ck-l ck-l0'); L.base.style.background = 'linear-gradient(160deg,' + hexA(col, .34) + ',#0a1020 62%)';
|
|
331
|
+
L.bg = el('div', 'ck-l ck-l1'); L.light = el('div', 'ck-l ck-l2'); L.props = el('div', 'ck-l ck-l3'); L.cast = el('div', 'ck-l ck-l4'); L.fx = el('div', 'ck-l ck-l5');
|
|
332
|
+
L.bubbles = el('div', 'ck-bubbles'); L.badge = el('div', 'ck-badge'); L.chip = el('div', 'ck-chip');
|
|
333
|
+
L.badge.appendChild(el('b', 'ck-seq', pad2(beat.seq))); L.badge.appendChild(el('span', 'ck-ttl', beat.title));
|
|
334
|
+
[L.base, L.bg, L.light, L.props, L.cast, L.fx, L.bubbles, L.badge, L.chip].forEach(function (n) { p.appendChild(n); });
|
|
335
|
+
var x = {panel: p, layers: L, beat: beat, hdr: null, meta: metaOf(beat),
|
|
336
|
+
sig: {scene: sceneSig(beat), cast: castSig(beat), lines: lineSig(beat), chip: chipSig(beat), title: beat.title}};
|
|
337
|
+
fillScene(x, beat); fillCast(x, beat); fillLines(x, beat); fillChip(x, beat);
|
|
338
|
+
if (animate && motion !== 'static') { p.classList.add('ck-enter'); p.style.setProperty('--d', Math.min(stagger || 0, 6) * 90 + 'ms'); }
|
|
339
|
+
return x;
|
|
340
|
+
}
|
|
341
|
+
function buildHeader(ep) {
|
|
342
|
+
var h = el('header', 'ck-ep', null, {role: 'heading', 'aria-level': '2'});
|
|
343
|
+
h.appendChild(el('span', 'ck-ep-n', 'TẬP ' + ep.index));
|
|
344
|
+
h.appendChild(el('span', 'ck-ep-t', String(ep.title || '').replace(/^\s*Tập\s*\d+\s*[:\-–·]\s*/i, '')));
|
|
345
|
+
h.setAttribute('data-ep', ep.id);
|
|
346
|
+
return h;
|
|
347
|
+
}
|
|
348
|
+
function epOf(beat) { for (var i = 0; i < story.episodes.length; i++) if (story.episodes[i].id === beat.episodeId) return story.episodes[i]; return null; }
|
|
349
|
+
function indexOfBeat(b) { var i = b.seq - 1; return story.beats[i] === b ? i : story.beats.indexOf(b); }
|
|
350
|
+
|
|
351
|
+
function addAt(idx, animate, stagger, before) {
|
|
352
|
+
var beat = story.beats[idx]; if (!beat || els[idx]) return;
|
|
353
|
+
var x = buildPanel(idx, beat, animate, stagger), ep = epOf(beat);
|
|
354
|
+
if (ep && ep.beatIds[0] === beat.id) { x.hdr = buildHeader(ep); if (animate && motion !== 'static') x.hdr.classList.add('ck-enter'); }
|
|
355
|
+
els[idx] = x; byId[beat.id] = idx;
|
|
356
|
+
if (before) { if (x.hdr) grid.insertBefore(x.hdr, before); grid.insertBefore(x.panel, before); }
|
|
357
|
+
else { if (x.hdr) grid.appendChild(x.hdr); grid.appendChild(x.panel); }
|
|
358
|
+
}
|
|
359
|
+
function removeAt(idx) { var x = els[idx]; if (!x) return; if (x.hdr) x.hdr.remove(); x.panel.remove(); delete byId[x.beat.id]; delete els[idx]; }
|
|
360
|
+
|
|
361
|
+
/* ---- layout (spans) ---- */
|
|
362
|
+
function widthNow() { var w = root.clientWidth; return w > 0 ? w : (lastWidthClass === 'narrow' ? 600 : 1200); }
|
|
363
|
+
function applySpans(full) {
|
|
364
|
+
if (!hi) return;
|
|
365
|
+
var rows = Eng.layoutRows(story.beats.slice(Math.max(0, lo - 2)), {width: widthNow()}), span = {};
|
|
366
|
+
rows.forEach(function (r) { r.items.forEach(function (it) { span[it.beatId] = it.span; }); });
|
|
367
|
+
for (var i = lo; i < hi; i++) {
|
|
368
|
+
var x = els[i]; if (!x) continue; var s = span[x.beat.id] || 12;
|
|
369
|
+
if (x.span !== s || full) { x.span = s; x.panel.style.gridColumn = 'span ' + s; x.panel.setAttribute('data-span', String(s)); }
|
|
370
|
+
if (x.hdr && !x.hdr.style.gridColumn) x.hdr.style.gridColumn = '1 / -1';
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/* ---- capsule ---- */
|
|
375
|
+
function findPrior(idx, ref) {
|
|
376
|
+
if (!ref) return -1;
|
|
377
|
+
for (var i = idx - 1; i >= lo; i--) { var x = els[i]; if (x && (x.meta.agents[ref] || x.meta.team === ref)) return i; }
|
|
378
|
+
return -1;
|
|
379
|
+
}
|
|
380
|
+
function capsule(idx) {
|
|
381
|
+
var x = els[idx], t = x && x.beat.transfer;
|
|
382
|
+
if (!t || motion !== 'full' || history || anims.length >= MAX_ANIM) return;
|
|
383
|
+
var s = findPrior(idx, t.from); if (s < 0) s = findPrior(idx, 'director'); if (s < 0 || !els[s]) return;
|
|
384
|
+
var a = els[s].panel.getBoundingClientRect(), b = x.panel.getBoundingClientRect();
|
|
385
|
+
if (!a.width || !b.width || typeof Element.prototype.animate !== 'function') return;
|
|
386
|
+
var c = el('div', 'ck-capsule'), ps = M && M.props && M.props.capsule && comicSrc(M.props.capsule.src);
|
|
387
|
+
if (ps) c.appendChild(img(ps, 'ck-capimg')); else c.classList.add('plain');
|
|
388
|
+
c.style.setProperty('--pc', x.panel.style.getPropertyValue('--pc'));
|
|
389
|
+
root.appendChild(c);
|
|
390
|
+
var x0 = a.left + a.width / 2, y0 = a.top + a.height / 2, x1 = b.left + b.width / 2, y1 = b.top + b.height / 2;
|
|
391
|
+
var cx = (x0 + x1) / 2 + (y1 - y0) * .25, cy = Math.min(y0, y1) - 60 - Math.abs(x1 - x0) * .1, kf = [], n = 14;
|
|
392
|
+
for (var i = 0; i <= n; i++) {
|
|
393
|
+
var u = i / n, px = (1 - u) * (1 - u) * x0 + 2 * (1 - u) * u * cx + u * u * x1, py = (1 - u) * (1 - u) * y0 + 2 * (1 - u) * u * cy + u * u * y1;
|
|
394
|
+
kf.push({transform: 'translate(' + (px - 14).toFixed(1) + 'px,' + (py - 14).toFixed(1) + 'px) scale(' + (0.7 + 0.5 * Math.sin(u * Math.PI)).toFixed(2) + ')', opacity: i === 0 || i === n ? 0 : 1});
|
|
395
|
+
}
|
|
396
|
+
var an = c.animate(kf, {duration: 900, easing: 'ease-in-out', fill: 'forwards'});
|
|
397
|
+
anims.push(an);
|
|
398
|
+
var done = function () { var k = anims.indexOf(an); if (k >= 0) anims.splice(k, 1); c.remove(); };
|
|
399
|
+
an.onfinish = done; an.oncancel = done;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/* ---- flush: apply pending beats ---- */
|
|
403
|
+
function nearBottom() { return root.scrollHeight - root.scrollTop - root.clientHeight <= NEAR_PX; }
|
|
404
|
+
function visible() { return root.offsetParent !== null || root.clientHeight > 0; }
|
|
405
|
+
function scrollBottom(smooth) { var top = root.scrollHeight; if (smooth && motion === 'full' && root.scrollTo) root.scrollTo({top: top, behavior: 'smooth'}); else root.scrollTop = top; }
|
|
406
|
+
function updateCount() {
|
|
407
|
+
var n = story.beats.length, e = story.episodes.length; count.textContent = n ? n + ' cảnh · ' + e + ' tập' : '';
|
|
408
|
+
empty.hidden = n > 0;
|
|
409
|
+
}
|
|
410
|
+
function updateMore() { more.hidden = lo <= 0; more.textContent = 'Xem ' + lo + ' cảnh trước'; }
|
|
411
|
+
function updateChip() { newChip.hidden = !(unseen > 0) || history; newChip.textContent = 'Có cảnh mới ↓' + (unseen > 1 ? ' (' + unseen + ')' : ''); }
|
|
412
|
+
|
|
413
|
+
function flush() {
|
|
414
|
+
scheduled = false; lastFlush = Date.now();
|
|
415
|
+
if (!M) return;
|
|
416
|
+
var added = pendingAdded, upd = pendingUpdated; pendingAdded = []; pendingUpdated = [];
|
|
417
|
+
var wasNear = nearBottom(), total = story.beats.length, n0 = hi, shown = visible();
|
|
418
|
+
if (total > hi) {
|
|
419
|
+
if (total - hi > cap) { for (var r = lo; r < hi; r++) removeAt(r); hi = total - cap; lo = hi; }
|
|
420
|
+
var animate = !history && shown && motion !== 'static';
|
|
421
|
+
for (var i = hi; i < total; i++) { try { addAt(i, animate, i - Math.max(hi, total - 6)); } catch (err) { if (window.console) console.error(err); } }
|
|
422
|
+
hi = total;
|
|
423
|
+
while (hi - lo > cap) { removeAt(lo); lo++; }
|
|
424
|
+
applySpans(false);
|
|
425
|
+
updateMore();
|
|
426
|
+
}
|
|
427
|
+
upd.forEach(function (b) {
|
|
428
|
+
var idx = indexOfBeat(b), x = els[idx]; if (!x || idx >= n0 && added.indexOf(b) >= 0) return;
|
|
429
|
+
try { patch(x, b); } catch (err) { if (window.console) console.error(err); }
|
|
430
|
+
});
|
|
431
|
+
patchHeaders();
|
|
432
|
+
updateCount(); syncShimmer();
|
|
433
|
+
var newPanels = hi - n0;
|
|
434
|
+
if (newPanels > 0 && !history) {
|
|
435
|
+
if (follow && wasNear) { raf(function () { scrollBottom(true); }); }
|
|
436
|
+
else if (shown) { unseen += newPanels; updateChip(); }
|
|
437
|
+
added.forEach(function (b) { var idx = indexOfBeat(b); if (b.transfer && els[idx]) raf(function () { capsule(idx); }); });
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
function patch(x, b) {
|
|
441
|
+
x.beat = b; var s = x.sig;
|
|
442
|
+
if (s.scene !== sceneSig(b)) { s.scene = sceneSig(b); fillScene(x, b); }
|
|
443
|
+
if (s.cast !== castSig(b)) { s.cast = castSig(b); fillCast(x, b); x.meta = metaOf(b); }
|
|
444
|
+
if (s.lines !== lineSig(b)) { s.lines = lineSig(b); fillLines(x, b); }
|
|
445
|
+
if (s.chip !== chipSig(b)) { s.chip = chipSig(b); fillChip(x, b); }
|
|
446
|
+
if (s.title !== b.title) { s.title = b.title; x.layers.badge.querySelector('.ck-ttl').textContent = b.title; x.panel.setAttribute('aria-label', 'Cảnh ' + b.seq + ': ' + b.title); }
|
|
447
|
+
}
|
|
448
|
+
function patchHeaders() {
|
|
449
|
+
for (var i = lo; i < hi; i++) {
|
|
450
|
+
var x = els[i]; if (!x || !x.hdr) continue; var ep = epOf(x.beat); if (!ep) continue;
|
|
451
|
+
var t = String(ep.title || '').replace(/^\s*Tập\s*\d+\s*[:\-–·]\s*/i, ''), tn = x.hdr.querySelector('.ck-ep-t');
|
|
452
|
+
if (tn && tn.textContent !== t) tn.textContent = t;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
function schedule() {
|
|
456
|
+
if (scheduled || destroyed) return; scheduled = true;
|
|
457
|
+
var wait = Math.max(0, FLUSH_MS - (Date.now() - lastFlush));
|
|
458
|
+
later(function () { raf(flush); }, wait);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/* ---- reader controls ---- */
|
|
462
|
+
function renderedIdx() { var a = []; for (var i = lo; i < hi; i++) if (els[i]) a.push(i); return a; }
|
|
463
|
+
function setFocus(i, scroll) {
|
|
464
|
+
if (!els[i]) return;
|
|
465
|
+
if (els[focusIdx]) els[focusIdx].panel.classList.remove('is-focus');
|
|
466
|
+
focusIdx = i; els[i].panel.classList.add('is-focus');
|
|
467
|
+
if (scroll) { var smooth = motion === 'full'; els[i].panel.scrollIntoView({block: 'center', behavior: smooth ? 'smooth' : 'auto'}); }
|
|
468
|
+
}
|
|
469
|
+
function step(d) {
|
|
470
|
+
var a = renderedIdx(); if (!a.length) return;
|
|
471
|
+
var k = a.indexOf(focusIdx); k = k < 0 ? (d > 0 ? 0 : a.length - 1) : Math.max(0, Math.min(a.length - 1, k + d));
|
|
472
|
+
setFocus(a[k], true); els[a[k]].panel.focus({preventScroll: true});
|
|
473
|
+
return k === a.length - 1;
|
|
474
|
+
}
|
|
475
|
+
function setPlaying(on) {
|
|
476
|
+
playing = on; if (playTimer) { clearInterval(playTimer); playTimer = 0; }
|
|
477
|
+
bPlay.textContent = on ? '⏸ Tạm dừng xem lại' : '⏯ Phát lại'; bPlay.setAttribute('aria-pressed', on ? 'true' : 'false');
|
|
478
|
+
if (on) playTimer = setInterval(function () { if (destroyed) return; var a = renderedIdx(); if (!a.length || focusIdx === a[a.length - 1]) { setPlaying(false); return; } step(1); }, 3000 / speed);
|
|
479
|
+
}
|
|
480
|
+
function setSpeed(v) { speed = v; speedBtns.forEach(function (b, i) { b.setAttribute('aria-pressed', [0.5, 1, 2][i] === v ? 'true' : 'false'); }); if (playing) setPlaying(true); }
|
|
481
|
+
bPrev.onclick = function () { step(-1); };
|
|
482
|
+
bNext.onclick = function () { step(1); };
|
|
483
|
+
bPlay.onclick = function () { if (!playing && focusIdx < 0) { var a = renderedIdx(); if (a.length) setFocus(a[0], true); } setPlaying(!playing); };
|
|
484
|
+
followCb.onchange = function () { follow = followCb.checked; if (follow && nearBottom()) { unseen = 0; updateChip(); } };
|
|
485
|
+
newChip.onclick = function () { unseen = 0; follow = true; followCb.checked = true; updateChip(); scrollBottom(true); };
|
|
486
|
+
more.onclick = function () {
|
|
487
|
+
var first = els[lo], from = Math.max(0, lo - CHUNK), before = first ? (first.hdr || first.panel) : null, top = root.scrollHeight;
|
|
488
|
+
for (var i = lo - 1; i >= from; i--) { /* build in reverse so each goes before the previous */
|
|
489
|
+
var b0 = els[i + 1] ? (els[i + 1].hdr || els[i + 1].panel) : before; addAt(i, false, 0, b0);
|
|
490
|
+
}
|
|
491
|
+
cap += lo - from; lo = from; applySpans(true); updateMore(); root.scrollTop += root.scrollHeight - top;
|
|
492
|
+
};
|
|
493
|
+
root.addEventListener('scroll', function () { if (unseen && nearBottom()) { unseen = 0; updateChip(); } }, {passive: true});
|
|
494
|
+
root.addEventListener('keydown', function (ev) {
|
|
495
|
+
var t = ev.target, tag = t && t.tagName; if (tag === 'INPUT' || tag === 'SELECT' || tag === 'TEXTAREA' || ev.altKey || ev.ctrlKey || ev.metaKey) return;
|
|
496
|
+
if (modal) return;
|
|
497
|
+
if (ev.key === 'ArrowRight') { ev.preventDefault(); step(1); }
|
|
498
|
+
else if (ev.key === 'ArrowLeft') { ev.preventDefault(); step(-1); }
|
|
499
|
+
else if (ev.key === ' ' && tag !== 'BUTTON') { ev.preventDefault(); bPlay.click(); }
|
|
500
|
+
});
|
|
501
|
+
grid.addEventListener('focusin', function (ev) {
|
|
502
|
+
var p = ev.target.closest && ev.target.closest('.ck-panel'); if (!p) return;
|
|
503
|
+
var idx = byId[p.getAttribute('data-beat')]; if (idx != null && idx !== focusIdx) setFocus(idx, false);
|
|
504
|
+
});
|
|
505
|
+
grid.addEventListener('pointermove', function (ev) {
|
|
506
|
+
if (motion !== 'full' || ev.pointerType === 'touch') return;
|
|
507
|
+
var p = ev.target.closest && ev.target.closest('.ck-panel'); if (!p) return;
|
|
508
|
+
var r = p.getBoundingClientRect(); parEl = p; parX = (ev.clientX - r.left) / r.width - .5; parY = (ev.clientY - r.top) / r.height - .5;
|
|
509
|
+
if (!parRaf) parRaf = requestAnimationFrame(function () { parRaf = 0; if (parEl && !destroyed) { parEl.style.setProperty('--mx', (parX * 8).toFixed(1) + 'px'); parEl.style.setProperty('--my', (parY * 5).toFixed(1) + 'px'); } });
|
|
510
|
+
});
|
|
511
|
+
grid.addEventListener('pointerleave', function () { if (parEl) { parEl.style.setProperty('--mx', '0px'); parEl.style.setProperty('--my', '0px'); } });
|
|
512
|
+
|
|
513
|
+
/* ---- source inspector ---- */
|
|
514
|
+
var modal = null;
|
|
515
|
+
function closeInspector() { if (!modal) return; modal.remove(); modal = null; if (openedFrom && document.body.contains(openedFrom)) openedFrom.focus(); openedFrom = null; }
|
|
516
|
+
function showInspector(beat, line) {
|
|
517
|
+
closeInspector();
|
|
518
|
+
var m = el('div', 'ck-modal', null, {role: 'dialog', 'aria-modal': 'true', 'aria-label': 'Nguyên văn · cảnh ' + beat.seq});
|
|
519
|
+
var card = el('div', 'ck-mcard'), hd = el('div', 'ck-mhd'), close = el('button', 'ck-b', '✕ Đóng', {type: 'button'});
|
|
520
|
+
hd.appendChild(el('b', '', pad2(beat.seq) + ' · ' + beat.title)); hd.appendChild(close);
|
|
521
|
+
var tabs = el('div', 'ck-tabs', null, {role: 'tablist'}), body = el('div', 'ck-mbody');
|
|
522
|
+
var views = {};
|
|
523
|
+
function lineText() { var f = line && (line.full || line.text); return f != null ? String(f) : beat.lines.map(function (l) { return l.full || l.text; }).join('\n\n'); }
|
|
524
|
+
views.story = function () {
|
|
525
|
+
var d = el('div', 'ck-story'); d.appendChild(el('p', 'ck-sm', beat.status || ''));
|
|
526
|
+
beat.lines.forEach(function (l) { var q = el('p', 'ck-sl k-' + l.kind); q.appendChild(el('b', '', (l.speakerId ? infoOf(l.speakerId).name : 'Dẫn truyện') + ' · ' + l.kind + ': ')); q.appendChild(document.createTextNode(l.text)); d.appendChild(q); });
|
|
527
|
+
return d;
|
|
528
|
+
};
|
|
529
|
+
views.detail = function () {
|
|
530
|
+
var dl = el('dl', 'ck-dl'), f = [['id', beat.id], ['seq', beat.seq], ['episode', beat.episodeId], ['type', beat.type], ['team', beat.team], ['scene', beat.scene], ['truth', beat.truth], ['status', beat.status], ['open', beat.open], ['transfer', beat.transfer ? beat.transfer.from + ' → ' + beat.transfer.to : '-'], ['sourceSeqs', (beat.sourceSeqs || []).join(', ')], ['at', beat.at], ['endAt', beat.endAt]];
|
|
531
|
+
f.forEach(function (kv) { dl.appendChild(el('dt', '', kv[0])); dl.appendChild(el('dd', '', String(kv[1]))); });
|
|
532
|
+
return dl;
|
|
533
|
+
};
|
|
534
|
+
views.raw = function () { return el('pre', 'ck-pre', lineText()); };
|
|
535
|
+
var tabBtns = {};
|
|
536
|
+
[['story', 'Story'], ['detail', 'Chi tiết'], ['raw', 'Nguyên văn']].forEach(function (t) {
|
|
537
|
+
var b = el('button', 'ck-tab', t[1], {type: 'button', role: 'tab'}); tabBtns[t[0]] = b; tabs.appendChild(b);
|
|
538
|
+
b.onclick = function () { Object.keys(tabBtns).forEach(function (k) { tabBtns[k].setAttribute('aria-selected', k === t[0] ? 'true' : 'false'); }); body.textContent = ''; body.appendChild(views[t[0]]()); };
|
|
539
|
+
});
|
|
540
|
+
card.appendChild(hd); card.appendChild(tabs); card.appendChild(body); m.appendChild(card);
|
|
541
|
+
close.onclick = closeInspector;
|
|
542
|
+
m.addEventListener('click', function (ev) { if (ev.target === m) closeInspector(); });
|
|
543
|
+
m.addEventListener('keydown', function (ev) { if (ev.key === 'Escape') { ev.stopPropagation(); closeInspector(); } });
|
|
544
|
+
root.appendChild(m); modal = m; tabBtns[line && line.full ? 'raw' : 'story'].click(); close.focus();
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/* ---- resize ---- */
|
|
548
|
+
var resizeT = 0;
|
|
549
|
+
ro(root, function () {
|
|
550
|
+
var w = root.clientWidth; if (!w) return;
|
|
551
|
+
var cls = w < 900 ? 'narrow' : 'wide';
|
|
552
|
+
if (cls === lastWidthClass) return;
|
|
553
|
+
var first = lastWidthClass === null; lastWidthClass = cls;
|
|
554
|
+
if (resizeT) { clearTimeout(timers[resizeT]); delete timers[resizeT]; }
|
|
555
|
+
resizeT = later(function () { resizeT = 0; root.setAttribute('data-cols', cls); applySpans(true); }, first ? 0 : 160);
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
/* ---- public ---- */
|
|
559
|
+
loadManifests().then(function (m) { M = m; if (destroyed) return; if (story.beats.length > hi) schedule(); });
|
|
560
|
+
|
|
561
|
+
function push(event) {
|
|
562
|
+
if (destroyed || !event) return;
|
|
563
|
+
var r; try { r = story.push(event); } catch (e) { if (window.console) console.error(e); return; }
|
|
564
|
+
if (!r) return;
|
|
565
|
+
(r.added || []).forEach(function (b) { pendingAdded.push(b); });
|
|
566
|
+
(r.updated || []).forEach(function (b) { pendingUpdated.push(b); });
|
|
567
|
+
if (!(r.added && r.added.length) && !(r.updated && r.updated.length)) return;
|
|
568
|
+
updateCount(); schedule();
|
|
569
|
+
}
|
|
570
|
+
function reset() {
|
|
571
|
+
clearTimers(); closeInspector();
|
|
572
|
+
story.reset(); grid.textContent = ''; els = {}; byId = {}; lo = 0; hi = 0; cap = MAX_PANELS; shimmering = [];
|
|
573
|
+
pendingAdded = []; pendingUpdated = []; scheduled = false; unseen = 0; focusIdx = -1; playing = false; bPlay.textContent = '⏯ Phát lại';
|
|
574
|
+
resizeT = 0; updateCount(); updateMore(); updateChip();
|
|
575
|
+
root.scrollTop = 0;
|
|
576
|
+
}
|
|
577
|
+
function setHistory(on) {
|
|
578
|
+
on = !!on; if (on === history) return; history = on;
|
|
579
|
+
root.classList.toggle('is-history', on); histBadge.hidden = !on; replay.hidden = !on;
|
|
580
|
+
if (on) { unseen = 0; updateChip(); } else { setPlaying(false); if (els[focusIdx]) els[focusIdx].panel.classList.remove('is-focus'); focusIdx = -1; if (follow) raf(function () { scrollBottom(false); }); }
|
|
581
|
+
updateChip();
|
|
582
|
+
}
|
|
583
|
+
function setContext(ctx) { try { story.setContext(ctx); } catch (e) { if (window.console) console.error(e); } }
|
|
584
|
+
function destroy() {
|
|
585
|
+
if (destroyed) return; clearTimers(); destroyed = true;
|
|
586
|
+
ros.forEach(function (o) { try { o.disconnect(); } catch (e) { /* ignore */ } }); ros = [];
|
|
587
|
+
closeInspector(); root.textContent = ''; root.classList.remove('ck-root', 'is-history'); root.removeAttribute('data-motion'); els = {}; byId = {};
|
|
588
|
+
}
|
|
589
|
+
updateCount(); updateMore();
|
|
590
|
+
return {push: push, reset: reset, setContext: setContext, setHistory: setHistory, setMotion: function (m) { setMotion(m, true); }, destroy: destroy, story: story};
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
window.CKComic = {create: create, _safeSrc: safeSrc};
|
|
594
|
+
})();
|