@mayder/devibe 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/anatomy.mjs +146 -0
- package/dist/devibe.svg +4 -0
- package/dist/graphify.js +20 -6
- package/dist/model.js +9 -0
- package/dist/server.js +20 -3
- package/dist/vendor/anatomy/LICENSE +21 -0
- package/dist/vendor/anatomy/README.md +3 -0
- package/dist/vendor/anatomy/iso-kit.mjs +674 -0
- package/dist/viewer.html +153 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
**Vibe code checker.** Entiende qué escribió tu IA y revisa sus cambios en tu repo local. Elige un punto de entrada, sigue el recorrido y abre el fragmento que explica cada paso.
|
|
4
4
|
|
|
5
|
-
[Sitio de DeVibe](https://devibe-xi.vercel.app/) · [Demo pública](https://devibe-xi.vercel.app/demo/)
|
|
5
|
+
[Sitio de DeVibe](https://devibe-xi.vercel.app/) · [Demo pública](https://devibe-xi.vercel.app/demo/) · [Paquete en npm](https://www.npmjs.com/package/@mayder/devibe)
|
|
6
6
|
|
|
7
7
|
## Probar la demo
|
|
8
8
|
|
|
@@ -44,4 +44,4 @@ El visor ofrece tema claro verde lima y tema oscuro. El tema de código **DeVibe
|
|
|
44
44
|
|
|
45
45
|
## Estado
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
DeVibe explora llamadas estáticas y cambios locales. En un repo abierto con Graphify puedes alternar entre **Isométrico**, **Anatomy** y **Pasos**. Las explicaciones de funciones con IA siguen en el plan de Learn.
|
package/dist/anatomy.mjs
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { boxCorners, cylinder, depthOf, fitProjection, iso, pathOf, slabOf, solidSvg } from './vendor/anatomy/iso-kit.mjs'
|
|
2
|
+
|
|
3
|
+
const cameras = { diagonal: [37, 33, -50], opposite: [53, 33, 50], high: [45, 57, -30] }
|
|
4
|
+
const symbols = {
|
|
5
|
+
function: ['Función', 'M15 4H12C10 4 9 6 9 8L7 16C7 18 6 20 4 20H2M5 11H14'],
|
|
6
|
+
method: ['Método', 'M3 5H9V11H3ZM15 13H21V19H15ZM6 11V16H15M14 5H21M14 8H19'],
|
|
7
|
+
class: ['Clase', 'M3 5L12 2L21 5L12 8ZM3 5V14L12 18L21 14V5M12 8V18'],
|
|
8
|
+
module: ['Módulo', 'M3 6H10L12 8H21V19H3ZM3 12H21'],
|
|
9
|
+
database: ['Base de datos', 'M4 6C4 2 20 2 20 6S4 10 4 6ZM4 6V18C4 22 20 22 20 18V6M4 12C4 16 20 16 20 12'],
|
|
10
|
+
network: ['Red', 'M3 8Q12 0 21 8M6 12Q12 6 18 12M9 16Q12 13 15 16M12 19V21'],
|
|
11
|
+
symbol: ['Símbolo', 'M8 5L2 12L8 19M16 5L22 12L16 19M14 4L10 20'],
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function hasPath(edges, start, target) {
|
|
15
|
+
const pending = [start]
|
|
16
|
+
const visited = new Set()
|
|
17
|
+
while (pending.length) {
|
|
18
|
+
const next = pending.pop()
|
|
19
|
+
if (next === target) return true
|
|
20
|
+
if (visited.has(next)) continue
|
|
21
|
+
visited.add(next)
|
|
22
|
+
for (const edge of edges) if (edge.from.id === next) pending.push(edge.to.id)
|
|
23
|
+
}
|
|
24
|
+
return false
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function layoutAnatomy(flow, entry) {
|
|
28
|
+
const edges = flow.flatMap((step, index) => step.call ? [{ ...step.call, index, provenance: step.provenance }] : [])
|
|
29
|
+
const root = edges.find(edge => edge.from.id === entry)?.from
|
|
30
|
+
if (!root) return { nodes: [], edges: [] }
|
|
31
|
+
|
|
32
|
+
const nodes = new Map([[entry, { ...root, level: 0 }]])
|
|
33
|
+
for (const level of [1, 2]) {
|
|
34
|
+
for (const { from, to } of edges) {
|
|
35
|
+
if (nodes.get(from.id)?.level === level - 1 && !nodes.has(to.id)) nodes.set(to.id, { ...to, level })
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
for (const level of [0, 1, 2]) {
|
|
39
|
+
const column = [...nodes.values()].filter(node => node.level === level)
|
|
40
|
+
column.forEach((node, index) => {
|
|
41
|
+
node.row = index - (column.length - 1) / 2
|
|
42
|
+
node.indices = edges.filter(edge => edge.to.id === node.id || edge.from.id === node.id).map(edge => edge.index)
|
|
43
|
+
node.index = edges.find(edge => level ? edge.to.id === node.id : edge.from.id === node.id).index
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
const visible = edges.filter(edge => nodes.has(edge.from.id) && nodes.has(edge.to.id))
|
|
47
|
+
for (const edge of visible) {
|
|
48
|
+
edge.cycle = nodes.get(edge.to.id).level <= nodes.get(edge.from.id).level && hasPath(visible, edge.to.id, edge.from.id)
|
|
49
|
+
}
|
|
50
|
+
return { nodes: [...nodes.values()], edges: visible }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function drawGrid(plans, projection) {
|
|
54
|
+
const lowX = Math.min(...plans.map(plan => plan.x)) - 44
|
|
55
|
+
const highX = Math.max(...plans.map(plan => plan.x)) + 44
|
|
56
|
+
const lowY = Math.min(...plans.map(plan => plan.y)) - 44
|
|
57
|
+
const highY = Math.max(...plans.map(plan => plan.y)) + 44
|
|
58
|
+
const line = corners => pathOf(corners.map(corner => iso([...corner, -2], projection)))
|
|
59
|
+
let grid = `<path class="ar-floor" d="${line([[lowX, lowY], [highX, lowY], [highX, highY], [lowX, highY], [lowX, lowY]])}"/>`
|
|
60
|
+
for (let x = lowX + 24; x < highX; x += 24) grid += `<path class="ar-gridline" d="${line([[x, lowY], [x, highY]])}"/>`
|
|
61
|
+
for (let y = lowY + 24; y < highY; y += 24) grid += `<path class="ar-gridline" d="${line([[lowX, y], [highX, y]])}"/>`
|
|
62
|
+
return grid
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function renderGraphMap(stage, flow, entry, { view, camera }) {
|
|
66
|
+
const { nodes, edges } = layoutAnatomy(flow, entry)
|
|
67
|
+
if (!nodes.length) return undefined
|
|
68
|
+
|
|
69
|
+
const classic = view === 'iso'
|
|
70
|
+
const [azimuth, elevation, slope] = classic ? cameras[camera] ?? cameras.diagonal : [45, 42, 10]
|
|
71
|
+
const angle = azimuth * Math.PI / 180
|
|
72
|
+
const width = 640
|
|
73
|
+
const rows = Math.max(...[0, 1, 2].map(level => nodes.filter(node => node.level === level).length))
|
|
74
|
+
const height = Math.max(classic ? 300 : 280, rows * 73 + 112)
|
|
75
|
+
const plans = nodes.map(node => {
|
|
76
|
+
const across = node.level * 175
|
|
77
|
+
const down = node.row * 112 + node.level * slope
|
|
78
|
+
return { ...node, x: across * Math.sin(angle) + down * Math.cos(angle), y: -across * Math.cos(angle) + down * Math.sin(angle), w: 65, d: 51, r: classic ? 1 : 5 }
|
|
79
|
+
})
|
|
80
|
+
const byId = new Map(plans.map(node => [node.id, node]))
|
|
81
|
+
const points = plans.flatMap(plan => boxCorners(plan, 0, 34))
|
|
82
|
+
const projection = fitProjection(points, width, height, { azimuth, elevation, pad: 64 })
|
|
83
|
+
const svg = stage.querySelector('svg')
|
|
84
|
+
const pins = stage.querySelector('.ar-anatomy-pins')
|
|
85
|
+
const connections = edges.map(({ from, to, index, provenance, cycle }) => {
|
|
86
|
+
const source = byId.get(from.id)
|
|
87
|
+
const target = byId.get(to.id)
|
|
88
|
+
const [sx, sy] = iso([source.x, source.y, 4], projection)
|
|
89
|
+
const [tx, ty] = iso([target.x, target.y, 4], projection)
|
|
90
|
+
const direction = Math.sign(tx - sx) || 1
|
|
91
|
+
const start = [sx + direction * 26, sy]
|
|
92
|
+
const end = [tx - direction * 36, ty]
|
|
93
|
+
const middle = (start[0] + end[0]) / 2
|
|
94
|
+
const route = cycle
|
|
95
|
+
? source === target
|
|
96
|
+
? `M ${sx + 20} ${sy} c 48 26 50 -56 13 -42`
|
|
97
|
+
: `M ${start.join(' ')} Q ${middle} ${Math.min(sy, ty) - 94} ${end.join(' ')}`
|
|
98
|
+
: pathOf(classic ? [start, end] : [start, [middle, sy], [middle, ty], end])
|
|
99
|
+
const classes = ['ar-anatomy-edge', provenance !== 'extracted' && 'ar-anatomy-uncertain', cycle && 'ar-anatomy-cycle'].filter(Boolean).join(' ')
|
|
100
|
+
return `<g class="${classes}" data-anatomy-edge="${index}"><path class="ar-anatomy-wire" d="${route}" marker-end="url(#ar-anatomy-arrow)"/><path class="ar-anatomy-hit" data-anatomy-edge="${index}" d="${route}"/></g>`
|
|
101
|
+
}).join('')
|
|
102
|
+
plans.sort((a, b) => depthOf([a.x, a.y, 0], projection) - depthOf([b.x, b.y, 0], projection))
|
|
103
|
+
const objects = plans.map(plan => {
|
|
104
|
+
const kind = Object.hasOwn(symbols, plan.kind) ? plan.kind : 'symbol'
|
|
105
|
+
const base = solidSvg(slabOf(plan, 0, 6, projection, 5, 1), { className: 'ar-anatomy-base' })
|
|
106
|
+
const slab = (w, d, z, h) => solidSvg(slabOf({ ...plan, w, d }, z, h, projection, 5, 1))
|
|
107
|
+
const disk = (z, h) => solidSvg(cylinder(plan.x, plan.y, 20, z, h, projection, 32, 1))
|
|
108
|
+
const [body, top] = {
|
|
109
|
+
function: () => [slab(46, 39, 6, 19) + slab(36, 28, 25, 6), 31],
|
|
110
|
+
method: () => [slab(43, 34, 6, 12) + slab(29, 24, 18, 10), 28],
|
|
111
|
+
class: () => [slab(48, 40, 6, 7) + slab(45, 36, 13, 8) + slab(41, 32, 21, 9), 30],
|
|
112
|
+
module: () => [slab(49, 42, 6, 14) + slab(35, 26, 20, 6), 26],
|
|
113
|
+
database: () => [disk(6, 10) + disk(16, 10) + disk(26, 10), 36],
|
|
114
|
+
network: () => [slab(44, 33, 6, 10) + slab(30, 24, 16, 16), 32],
|
|
115
|
+
symbol: () => [slab(40, 34, 6, 14), 20],
|
|
116
|
+
}[kind]()
|
|
117
|
+
const [x, y] = iso([plan.x, plan.y, top + 4], projection)
|
|
118
|
+
const pictogram = `<g class="ar-anatomy-glyph" transform="translate(${x - 10} ${y - 12}) scale(.83)"><circle cx="12" cy="12" r="15"/><path d="${symbols[kind][1]}"/></g>`
|
|
119
|
+
return `<g class="ar-anatomy-object" data-kind="${kind}" data-anatomy-indices="${plan.indices.join(' ')}" ${plan.level === 0 ? 'data-anatomy-root' : ''}>${base}${body}${pictogram}</g>`
|
|
120
|
+
}).join('')
|
|
121
|
+
|
|
122
|
+
stage.style.aspectRatio = `${width} / ${height}`
|
|
123
|
+
stage.dataset.graphView = view
|
|
124
|
+
svg.setAttribute('viewBox', `0 0 ${width} ${height}`)
|
|
125
|
+
svg.innerHTML = `<defs><marker id="ar-anatomy-arrow" markerWidth="6" markerHeight="6" refX="5" refY="3" orient="auto"><path d="M0 0L6 3L0 6Z" fill="context-stroke"/></marker></defs>${classic ? drawGrid(plans, projection) : ''}${connections}${objects}`
|
|
126
|
+
pins.replaceChildren(...nodes.map(node => {
|
|
127
|
+
const plan = byId.get(node.id)
|
|
128
|
+
const [x, y] = iso([plan.x, plan.y, 0], projection)
|
|
129
|
+
const button = document.createElement('button')
|
|
130
|
+
button.type = 'button'
|
|
131
|
+
button.dataset.step = node.index
|
|
132
|
+
button.dataset.anatomyIndices = node.indices.join(' ')
|
|
133
|
+
button.style.left = `${x / width * 100}%`
|
|
134
|
+
button.style.top = `${(y + 21) / height * 100}%`
|
|
135
|
+
const [kind] = Object.hasOwn(symbols, node.kind) ? symbols[node.kind] : symbols.symbol
|
|
136
|
+
button.title = `${node.label} · ${kind}`
|
|
137
|
+
const caption = document.createElement('strong')
|
|
138
|
+
caption.textContent = node.label
|
|
139
|
+
const role = document.createElement('small')
|
|
140
|
+
role.textContent = node.level === 0 ? `Entrada · ${kind.toLowerCase()}` : kind
|
|
141
|
+
button.append(caption, role)
|
|
142
|
+
if (node.level === 0) button.dataset.anatomyRoot = ''
|
|
143
|
+
return button
|
|
144
|
+
}))
|
|
145
|
+
return edges
|
|
146
|
+
}
|
package/dist/devibe.svg
ADDED
package/dist/graphify.js
CHANGED
|
@@ -3,17 +3,27 @@ import { access, mkdtemp, readFile, realpath, rm, stat } from 'node:fs/promises'
|
|
|
3
3
|
import { homedir, tmpdir } from 'node:os'
|
|
4
4
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path'
|
|
5
5
|
import { promisify } from 'node:util'
|
|
6
|
-
|
|
6
|
+
|
|
7
7
|
import { excerpt, LocalGitSource } from './source.js'
|
|
8
8
|
|
|
9
9
|
const exec = promisify(execFile)
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
|
|
14
12
|
|
|
15
13
|
|
|
16
14
|
|
|
15
|
+
const declaredKinds = new Set(['function', 'method', 'class', 'module', 'database', 'network'])
|
|
16
|
+
|
|
17
|
+
function symbolKind(label , declared ) {
|
|
18
|
+
if (declaredKinds.has(declared)) return declared
|
|
19
|
+
if (/^(?:postgres(?:ql)?|mysql|mongodb(?:\+srv)?|redis):\/\//i.test(label)) return 'database'
|
|
20
|
+
if (/^https?:\/\//i.test(label)) return 'network'
|
|
21
|
+
if (/^(?:[\w$]+)?\.[\w$]+\(\)$/.test(label)) return 'method'
|
|
22
|
+
if (/^[\w$]+\(\)$/.test(label)) return 'function'
|
|
23
|
+
if (/\.[cm]?[jt]sx?$|\.(?:py|rs|go|java|rb|php|cpp|cs)$/i.test(label)) return 'module'
|
|
24
|
+
return 'symbol'
|
|
25
|
+
}
|
|
26
|
+
|
|
17
27
|
|
|
18
28
|
|
|
19
29
|
|
|
@@ -29,7 +39,7 @@ export function parseGraph(value ) {
|
|
|
29
39
|
const nodes = new Map ()
|
|
30
40
|
for (const node of value.nodes) {
|
|
31
41
|
if (!node || typeof node.id !== 'string' || typeof node.label !== 'string') continue
|
|
32
|
-
nodes.set(node.id, { id: node.id, label: node.label, file: typeof node.source_file === 'string' ? node.source_file : undefined })
|
|
42
|
+
nodes.set(node.id, { id: node.id, label: node.label, kind: symbolKind(node.label, node.kind ?? node.type), file: typeof node.source_file === 'string' ? node.source_file : undefined })
|
|
33
43
|
}
|
|
34
44
|
const outgoing = new Map ()
|
|
35
45
|
for (const edge of value.links) {
|
|
@@ -122,7 +132,11 @@ export async function openGraphProject(path , options
|
|
|
122
132
|
const changedLine = patch?.hunks.some(hunk => hunk.lines.some(line => line.kind === 'add' && line.after === after?.focus))
|
|
123
133
|
const change = changedLine ? 'Línea añadida o editada' : file ? 'Archivo en el diff' : after ? 'Fuera del diff' : 'Sin ubicación verificada'
|
|
124
134
|
const description = `Graphify relaciona ${from.label} con ${to.label}.`
|
|
125
|
-
return {
|
|
135
|
+
return {
|
|
136
|
+
title: to.label, symbol: `${from.label} → ${to.label}`, icon: 'arrow-right-left', change,
|
|
137
|
+
explanation: description, effect: `${description} ${change}.`, after, provenance: edge.provenance,
|
|
138
|
+
call: { from: { id: from.id, label: from.label, kind: from.kind }, to: { id: to.id, label: to.label, kind: to.kind } },
|
|
139
|
+
}
|
|
126
140
|
}))
|
|
127
141
|
}
|
|
128
142
|
|
package/dist/model.js
CHANGED
package/dist/server.js
CHANGED
|
@@ -5,6 +5,10 @@ import { createServer } from 'node:http'
|
|
|
5
5
|
|
|
6
6
|
const uiPath = new URL('../../../work/atlas-review.html', import.meta.url)
|
|
7
7
|
const developmentHighlighterPath = new URL('../node_modules/@highlightjs/cdn-assets/highlight.min.js', import.meta.url)
|
|
8
|
+
const anatomyAssets = new Map([
|
|
9
|
+
['/anatomy.mjs', new URL('./anatomy.mjs', import.meta.url)],
|
|
10
|
+
['/vendor/anatomy/iso-kit.mjs', new URL('./vendor/anatomy/iso-kit.mjs', import.meta.url)],
|
|
11
|
+
])
|
|
8
12
|
|
|
9
13
|
export function renderPage(atlasCase , markup ) {
|
|
10
14
|
const data = JSON.stringify(atlasCase).replaceAll('<', '\\u003c')
|
|
@@ -14,7 +18,7 @@ export function renderPage(atlasCase , markup ) {
|
|
|
14
18
|
<meta charset="utf-8">
|
|
15
19
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
16
20
|
<title>DeVibe</title>
|
|
17
|
-
<link rel="icon" href="
|
|
21
|
+
<link rel="icon" type="image/svg+xml" href="./devibe.svg">
|
|
18
22
|
<style>
|
|
19
23
|
:root { color-scheme: light dark; }
|
|
20
24
|
:root[data-devibe-theme="light"] { color-scheme: light; }
|
|
@@ -47,7 +51,7 @@ export function renderPage(atlasCase , markup ) {
|
|
|
47
51
|
|
|
48
52
|
|
|
49
53
|
export async function startServer(atlasCase , inspection = {}) {
|
|
50
|
-
const [viewer, highlighter] = await Promise.all([
|
|
54
|
+
const [viewer, highlighter, brandIcon] = await Promise.all([
|
|
51
55
|
readFile(new URL('./viewer.html', import.meta.url), 'utf8').catch(error => {
|
|
52
56
|
if (error.code !== 'ENOENT') throw error
|
|
53
57
|
return readFile(uiPath, 'utf8')
|
|
@@ -56,12 +60,16 @@ export async function startServer(atlasCase , inspection
|
|
|
56
60
|
if (error.code !== 'ENOENT') throw error
|
|
57
61
|
return readFile(developmentHighlighterPath)
|
|
58
62
|
}),
|
|
63
|
+
readFile(new URL('./devibe.svg', import.meta.url)).catch(error => {
|
|
64
|
+
if (error.code !== 'ENOENT') throw error
|
|
65
|
+
return readFile(new URL('../site/devibe.svg', import.meta.url))
|
|
66
|
+
}),
|
|
59
67
|
])
|
|
60
68
|
const page = renderPage(atlasCase, viewer)
|
|
61
69
|
const json = JSON.stringify(atlasCase)
|
|
62
70
|
const server = createServer(async (request, response) => {
|
|
63
71
|
response.setHeader('Cache-Control', 'no-store')
|
|
64
|
-
response.setHeader('Content-Security-Policy', "default-src 'none'; script-src 'self' 'unsafe-inline'; style-src 'unsafe-inline'; img-src data:; connect-src 'self'; base-uri 'none'; frame-ancestors 'none'")
|
|
72
|
+
response.setHeader('Content-Security-Policy', "default-src 'none'; script-src 'self' 'unsafe-inline'; style-src 'unsafe-inline'; img-src 'self' data:; connect-src 'self'; base-uri 'none'; frame-ancestors 'none'")
|
|
65
73
|
const sendJson = (code , body ) => response.writeHead(code, { 'Content-Type': 'application/json; charset=utf-8' }).end(JSON.stringify(body))
|
|
66
74
|
const target = new URL(`http://127.0.0.1${request.url?.startsWith('/') ? request.url : '/'}`)
|
|
67
75
|
if (request.method !== 'GET') {
|
|
@@ -70,6 +78,15 @@ export async function startServer(atlasCase , inspection
|
|
|
70
78
|
response.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' }).end(page)
|
|
71
79
|
} else if (target.pathname === '/highlight.min.js') {
|
|
72
80
|
response.writeHead(200, { 'Content-Type': 'text/javascript; charset=utf-8' }).end(highlighter)
|
|
81
|
+
} else if (target.pathname === '/devibe.svg') {
|
|
82
|
+
response.writeHead(200, { 'Content-Type': 'image/svg+xml' }).end(brandIcon)
|
|
83
|
+
} else if (anatomyAssets.has(target.pathname)) {
|
|
84
|
+
try {
|
|
85
|
+
const code = await readFile(anatomyAssets.get(target.pathname) )
|
|
86
|
+
response.writeHead(200, { 'Content-Type': 'text/javascript; charset=utf-8' }).end(code)
|
|
87
|
+
} catch {
|
|
88
|
+
response.writeHead(404).end()
|
|
89
|
+
}
|
|
73
90
|
} else if (target.pathname === '/api/case') {
|
|
74
91
|
response.writeHead(200, { 'Content-Type': 'application/json; charset=utf-8' }).end(json)
|
|
75
92
|
} else if (target.pathname === '/api/flow' || target.pathname === '/api/patch') {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ryan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
# Anatomy
|
|
2
|
+
|
|
3
|
+
`iso-kit.mjs` procede de [Anatomy](https://github.com/wheresryan22/anatomy/blob/1482e8469b0a9e0d8cc18ea2740a01423d29ae80/kit/iso-kit.mjs), versión fijada en `1482e8469b0a9e0d8cc18ea2740a01423d29ae80`. Se incluye sin cambios y se distribuye con su licencia MIT en `LICENSE`.
|
|
@@ -0,0 +1,674 @@
|
|
|
1
|
+
export const AZIMUTH = 45;
|
|
2
|
+
export const ELEVATION = 30;
|
|
3
|
+
export const SHADES = 4;
|
|
4
|
+
const RADIANS = Math.PI / 180;
|
|
5
|
+
const UNIT = Math.sqrt(1.6);
|
|
6
|
+
export function cameraOf({ scale, azimuth = AZIMUTH, elevation = ELEVATION }) {
|
|
7
|
+
const a = azimuth * RADIANS;
|
|
8
|
+
const e = elevation * RADIANS;
|
|
9
|
+
return { sinA: Math.sin(a), cosA: Math.cos(a), sinE: Math.sin(e), cosE: Math.cos(e), k: scale * UNIT };
|
|
10
|
+
}
|
|
11
|
+
export function iso([x, y, z], projection) {
|
|
12
|
+
const { origin } = projection;
|
|
13
|
+
const { sinA, cosA, sinE, cosE, k } = cameraOf(projection);
|
|
14
|
+
return [origin[0] + (x * sinA - y * cosA) * k, origin[1] + ((x * cosA + y * sinA) * sinE - z * cosE) * k];
|
|
15
|
+
}
|
|
16
|
+
export function towardViewer(projection) {
|
|
17
|
+
const { sinA, cosA } = cameraOf(projection);
|
|
18
|
+
return [cosA, sinA];
|
|
19
|
+
}
|
|
20
|
+
export function depthOf([x, y, z], projection) {
|
|
21
|
+
const { sinA, cosA, sinE, cosE } = cameraOf(projection);
|
|
22
|
+
return (x * cosA + y * sinA) * cosE + z * sinE;
|
|
23
|
+
}
|
|
24
|
+
const tenth = (value) => {
|
|
25
|
+
const text = (Math.round(value * 10) / 10).toFixed(1).replace(/\.0$/, "");
|
|
26
|
+
return text === "-0" ? "0" : text;
|
|
27
|
+
};
|
|
28
|
+
export function pathOf(points, closed = false) {
|
|
29
|
+
if (!points.length)
|
|
30
|
+
return "";
|
|
31
|
+
return points.map(([x, y], at) => `${at ? "L" : "M"}${tenth(x)} ${tenth(y)}`).join("") + (closed ? "Z" : "");
|
|
32
|
+
}
|
|
33
|
+
export const joinPaths = (paths) => paths.filter(Boolean).join("");
|
|
34
|
+
export function roundedPlan({ x, y, w, d, r }, steps = 8) {
|
|
35
|
+
const radius = Math.max(0, Math.min(r, w / 2, d / 2));
|
|
36
|
+
const corners = [
|
|
37
|
+
[x + w - radius, y + radius, -90],
|
|
38
|
+
[x + w - radius, y + d - radius, 0],
|
|
39
|
+
[x + radius, y + d - radius, 90],
|
|
40
|
+
[x + radius, y + radius, 180],
|
|
41
|
+
];
|
|
42
|
+
const out = [];
|
|
43
|
+
for (const [cx, cy, start] of corners) {
|
|
44
|
+
const count = radius > 0 ? steps : 0;
|
|
45
|
+
for (let step = 0; step <= count; step++) {
|
|
46
|
+
const angle = (start + (count ? (90 * step) / count : 45)) * RADIANS;
|
|
47
|
+
out.push([cx + radius * Math.cos(angle), cy + radius * Math.sin(angle)]);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return out;
|
|
51
|
+
}
|
|
52
|
+
function signedArea(points) {
|
|
53
|
+
let area = 0;
|
|
54
|
+
for (let index = 0; index < points.length; index++) {
|
|
55
|
+
const [ax, ay] = points[index];
|
|
56
|
+
const [bx, by] = points[(index + 1) % points.length];
|
|
57
|
+
area += ax * by - bx * ay;
|
|
58
|
+
}
|
|
59
|
+
return area / 2;
|
|
60
|
+
}
|
|
61
|
+
const oriented = (points) => (signedArea(points) < 0 ? [...points].reverse() : points);
|
|
62
|
+
function convexHull(points) {
|
|
63
|
+
const sorted = [...points].sort((a, b) => a[0] - b[0] || a[1] - b[1]);
|
|
64
|
+
if (sorted.length < 3)
|
|
65
|
+
return sorted;
|
|
66
|
+
const cross = (o, a, b) => (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]);
|
|
67
|
+
const lower = [];
|
|
68
|
+
for (const point of sorted) {
|
|
69
|
+
while (lower.length >= 2 && cross(lower[lower.length - 2], lower[lower.length - 1], point) <= 0)
|
|
70
|
+
lower.pop();
|
|
71
|
+
lower.push(point);
|
|
72
|
+
}
|
|
73
|
+
const upper = [];
|
|
74
|
+
for (let index = sorted.length - 1; index >= 0; index--) {
|
|
75
|
+
const point = sorted[index];
|
|
76
|
+
while (upper.length >= 2 && cross(upper[upper.length - 2], upper[upper.length - 1], point) <= 0)
|
|
77
|
+
upper.pop();
|
|
78
|
+
upper.push(point);
|
|
79
|
+
}
|
|
80
|
+
return [...lower.slice(0, -1), ...upper.slice(0, -1)];
|
|
81
|
+
}
|
|
82
|
+
function runsOf(flags, want) {
|
|
83
|
+
const count = flags.length;
|
|
84
|
+
const runs = [];
|
|
85
|
+
const start = flags.findIndex((flag, index) => flag !== flags[(index + count - 1) % count]);
|
|
86
|
+
if (start < 0)
|
|
87
|
+
return flags[0] === want ? [Array.from({ length: count + 1 }, (_, index) => index % count)] : [];
|
|
88
|
+
let run = null;
|
|
89
|
+
for (let step = 0; step < count; step++) {
|
|
90
|
+
const index = (start + step) % count;
|
|
91
|
+
if (flags[index] === want) {
|
|
92
|
+
if (!run)
|
|
93
|
+
run = [index];
|
|
94
|
+
run.push((index + 1) % count);
|
|
95
|
+
}
|
|
96
|
+
else if (run) {
|
|
97
|
+
runs.push(run);
|
|
98
|
+
run = null;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (run)
|
|
102
|
+
runs.push(run);
|
|
103
|
+
return runs;
|
|
104
|
+
}
|
|
105
|
+
export function extrude(ring, z, height, projection, options = {}) {
|
|
106
|
+
const convex = options.convex ?? true;
|
|
107
|
+
const count = ring.length;
|
|
108
|
+
const counter = signedArea(ring) > 0;
|
|
109
|
+
const [vx, vy] = towardViewer(projection);
|
|
110
|
+
const { sinA, cosA } = cameraOf(projection);
|
|
111
|
+
const normals = ring.map(([ax, ay], index) => {
|
|
112
|
+
const [bx, by] = ring[(index + 1) % count];
|
|
113
|
+
const dx = bx - ax;
|
|
114
|
+
const dy = by - ay;
|
|
115
|
+
const length = Math.hypot(dx, dy) || 1;
|
|
116
|
+
return (counter ? [dy / length, -dx / length] : [-dy / length, dx / length]);
|
|
117
|
+
});
|
|
118
|
+
const facing = normals.map(([nx, ny]) => nx * vx + ny * vy > 1e-9);
|
|
119
|
+
const top = ring.map(([x, y]) => iso([x, y, z + height], projection));
|
|
120
|
+
const bottom = ring.map(([x, y]) => iso([x, y, z], projection));
|
|
121
|
+
const outline = [];
|
|
122
|
+
const crease = [];
|
|
123
|
+
for (const run of runsOf(facing, false))
|
|
124
|
+
outline.push(pathOf(run.map((index) => top[index])));
|
|
125
|
+
for (const run of runsOf(facing, true)) {
|
|
126
|
+
crease.push(pathOf(run.map((index) => top[index])));
|
|
127
|
+
if (height > 0)
|
|
128
|
+
outline.push(pathOf(run.map((index) => bottom[index])));
|
|
129
|
+
}
|
|
130
|
+
if (height > 0) {
|
|
131
|
+
for (let index = 0; index < count; index++) {
|
|
132
|
+
if (facing[(index + count - 1) % count] !== facing[index])
|
|
133
|
+
outline.push(pathOf([top[index], bottom[index]]));
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
let fill;
|
|
137
|
+
if (convex) {
|
|
138
|
+
fill = pathOf(convexHull([...top, ...bottom]), true);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
const parts = [pathOf(oriented(top), true), pathOf(oriented(bottom), true)];
|
|
142
|
+
for (let index = 0; index < count; index++) {
|
|
143
|
+
if (!facing[index])
|
|
144
|
+
continue;
|
|
145
|
+
const next = (index + 1) % count;
|
|
146
|
+
parts.push(pathOf(oriented([top[index], top[next], bottom[next], bottom[index]]), true));
|
|
147
|
+
}
|
|
148
|
+
fill = parts.join("");
|
|
149
|
+
}
|
|
150
|
+
const buckets = Array.from({ length: SHADES }, () => []);
|
|
151
|
+
if (height > 0) {
|
|
152
|
+
const [lx, ly] = [-sinA, cosA];
|
|
153
|
+
for (let index = 0; index < count; index++) {
|
|
154
|
+
if (!facing[index])
|
|
155
|
+
continue;
|
|
156
|
+
const [nx, ny] = normals[index];
|
|
157
|
+
const lit = (nx * lx + ny * ly + 1) / 2;
|
|
158
|
+
const shade = Math.min(SHADES - 1, Math.max(0, Math.floor(lit * SHADES)));
|
|
159
|
+
const next = (index + 1) % count;
|
|
160
|
+
buckets[shade].push(pathOf(oriented([top[index], top[next], bottom[next], bottom[index]]), true));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
let bevel;
|
|
164
|
+
if (options.bevel && options.bevel > 0) {
|
|
165
|
+
const by = options.bevel;
|
|
166
|
+
const inset = ring.map(([x, y], index) => {
|
|
167
|
+
const [ax, ay] = normals[(index + count - 1) % count];
|
|
168
|
+
const [bx, by2] = normals[index];
|
|
169
|
+
const mx = ax + bx;
|
|
170
|
+
const my = ay + by2;
|
|
171
|
+
const length = Math.hypot(mx, my) || 1;
|
|
172
|
+
return [x - (mx / length) * by, y - (my / length) * by];
|
|
173
|
+
});
|
|
174
|
+
const insetTop = inset.map(([x, y]) => iso([x, y, z + height], projection));
|
|
175
|
+
bevel = runsOf(facing, true)
|
|
176
|
+
.map((run) => pathOf([top[run[0]], ...run.slice(1, -1).map((index) => insetTop[index]), top[run[run.length - 1]]]))
|
|
177
|
+
.join("");
|
|
178
|
+
}
|
|
179
|
+
return {
|
|
180
|
+
fill,
|
|
181
|
+
outline: outline.join(""),
|
|
182
|
+
crease: crease.join(""),
|
|
183
|
+
top: pathOf(oriented(top), true),
|
|
184
|
+
shades: buckets.map((paths) => paths.join("")),
|
|
185
|
+
bevel,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
export const ringOf = (plan, steps = 8) => roundedPlan(plan, steps);
|
|
189
|
+
export function slabOf(plan, z, height, projection, steps = 8, bevel = 0) {
|
|
190
|
+
return extrude(ringOf(plan, steps), z, height, projection, { convex: true, bevel });
|
|
191
|
+
}
|
|
192
|
+
export function circleRing(cx, cy, radius, steps = 40) {
|
|
193
|
+
return Array.from({ length: steps }, (_, step) => {
|
|
194
|
+
const angle = (step / steps) * Math.PI * 2;
|
|
195
|
+
return [cx + radius * Math.cos(angle), cy + radius * Math.sin(angle)];
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
export function cylinder(cx, cy, radius, z, height, projection, steps = 32, bevel = 0) {
|
|
199
|
+
return extrude(circleRing(cx, cy, radius, steps), z, height, projection, { convex: true, bevel });
|
|
200
|
+
}
|
|
201
|
+
export const insetPlan = ({ x, y, w, d, r }, by) => ({ x: x + by, y: y + by, w: w - by * 2, d: d - by * 2, r: Math.max(0, r - by) });
|
|
202
|
+
export function onTop(points, z, projection, closed = false) {
|
|
203
|
+
return pathOf(points.map(([x, y]) => iso([x, y, z], projection)), closed);
|
|
204
|
+
}
|
|
205
|
+
export const planOutline = (plan, z, projection, steps = 8) => onTop(ringOf(plan, steps), z, projection, true);
|
|
206
|
+
export const lineOnTop = (from, to, z, projection) => onTop([from, to], z, projection);
|
|
207
|
+
export const segment = (from, to, projection) => pathOf([iso(from, projection), iso(to, projection)]);
|
|
208
|
+
export const rise = (at, from, to, projection) => segment([at[0], at[1], from], [at[0], at[1], to], projection);
|
|
209
|
+
export const ring = (cx, cy, radius, z, projection, steps = 40) => onTop(circleRing(cx, cy, radius, steps), z, projection, true);
|
|
210
|
+
export const pointsAt = (points, projection) => points.map((point) => iso(point, projection));
|
|
211
|
+
export function dotGrid(x, y, columns, rows, gap, z, projection) {
|
|
212
|
+
const dots = [];
|
|
213
|
+
for (let row = 0; row < rows; row++) {
|
|
214
|
+
for (let column = 0; column < columns; column++)
|
|
215
|
+
dots.push(iso([x + column * gap, y + row * gap, z], projection));
|
|
216
|
+
}
|
|
217
|
+
return dots;
|
|
218
|
+
}
|
|
219
|
+
export function corners({ x, y, w, d }, inset = 0) {
|
|
220
|
+
return [
|
|
221
|
+
[x + inset, y + inset],
|
|
222
|
+
[x + w - inset, y + inset],
|
|
223
|
+
[x + inset, y + d - inset],
|
|
224
|
+
[x + w - inset, y + d - inset],
|
|
225
|
+
];
|
|
226
|
+
}
|
|
227
|
+
export function boxCorners({ x, y, w, d }, z0, z1) {
|
|
228
|
+
const out = [];
|
|
229
|
+
for (const px of [x, x + w])
|
|
230
|
+
for (const py of [y, y + d])
|
|
231
|
+
for (const z of [z0, z1])
|
|
232
|
+
out.push([px, py, z]);
|
|
233
|
+
return out;
|
|
234
|
+
}
|
|
235
|
+
export function knurl(cx, cy, radius, z0, z1, count, projection, inset = 0.4) {
|
|
236
|
+
const [vx, vy] = towardViewer(projection);
|
|
237
|
+
const lines = [];
|
|
238
|
+
for (let index = 0; index < count; index++) {
|
|
239
|
+
const angle = (index / count) * Math.PI * 2;
|
|
240
|
+
const nx = Math.cos(angle);
|
|
241
|
+
const ny = Math.sin(angle);
|
|
242
|
+
if (nx * vx + ny * vy < 0.15)
|
|
243
|
+
continue;
|
|
244
|
+
lines.push(segment([cx + radius * nx, cy + radius * ny, z0 + inset], [cx + radius * nx, cy + radius * ny, z1 - inset], projection));
|
|
245
|
+
}
|
|
246
|
+
return lines.join("");
|
|
247
|
+
}
|
|
248
|
+
export function sideArc(cx, cy, radius, z, projection, steps = 24) {
|
|
249
|
+
const [vx, vy] = towardViewer(projection);
|
|
250
|
+
const facing = Math.atan2(vy, vx);
|
|
251
|
+
const points = [];
|
|
252
|
+
for (let step = 0; step <= steps; step++) {
|
|
253
|
+
const angle = facing - Math.PI / 2 + (step / steps) * Math.PI;
|
|
254
|
+
points.push(iso([cx + radius * Math.cos(angle), cy + radius * Math.sin(angle), z], projection));
|
|
255
|
+
}
|
|
256
|
+
return pathOf(points);
|
|
257
|
+
}
|
|
258
|
+
export function ringSeam(ring, z, projection) {
|
|
259
|
+
const count = ring.length;
|
|
260
|
+
const counter = signedArea(ring) > 0;
|
|
261
|
+
const [vx, vy] = towardViewer(projection);
|
|
262
|
+
const facing = ring.map(([ax, ay], index) => {
|
|
263
|
+
const [bx, by] = ring[(index + 1) % count];
|
|
264
|
+
const dx = bx - ax;
|
|
265
|
+
const dy = by - ay;
|
|
266
|
+
const [nx, ny] = counter ? [dy, -dx] : [-dy, dx];
|
|
267
|
+
return nx * vx + ny * vy > 1e-9;
|
|
268
|
+
});
|
|
269
|
+
return runsOf(facing, true).map((run) => pathOf(run.map((index) => iso([ring[index][0], ring[index][1], z], projection)))).join("");
|
|
270
|
+
}
|
|
271
|
+
export const sideSeam = (plan, z, projection, steps = 8) => ringSeam(ringOf(plan, steps), z, projection);
|
|
272
|
+
export function sideRing(center, radius, axis, projection, steps = 20) {
|
|
273
|
+
const [px, py, pz] = center;
|
|
274
|
+
const points = [];
|
|
275
|
+
for (let step = 0; step < steps; step++) {
|
|
276
|
+
const angle = (step / steps) * Math.PI * 2;
|
|
277
|
+
const u = radius * Math.cos(angle);
|
|
278
|
+
const v = radius * Math.sin(angle);
|
|
279
|
+
points.push(iso(axis === "x" ? [px, py + u, pz + v] : [px + u, py, pz + v], projection));
|
|
280
|
+
}
|
|
281
|
+
return pathOf(points, true);
|
|
282
|
+
}
|
|
283
|
+
export function coil(from, to, center, radius, turns, axis, projection, perTurn = 16) {
|
|
284
|
+
const count = Math.max(1, Math.round(turns * perTurn));
|
|
285
|
+
const back = [];
|
|
286
|
+
const front = [];
|
|
287
|
+
let run = [];
|
|
288
|
+
let near = null;
|
|
289
|
+
for (let index = 0; index <= count; index++) {
|
|
290
|
+
const share = index / count;
|
|
291
|
+
const angle = share * turns * Math.PI * 2;
|
|
292
|
+
const u = radius * Math.cos(angle);
|
|
293
|
+
const v = radius * Math.sin(angle);
|
|
294
|
+
const along = from + (to - from) * share;
|
|
295
|
+
const point = axis === "x" ? [along, center[0] + u, center[1] + v] : [center[0] + u, along, center[1] + v];
|
|
296
|
+
const normal = axis === "x" ? [0, Math.cos(angle), Math.sin(angle)] : [Math.cos(angle), 0, Math.sin(angle)];
|
|
297
|
+
const facing = depthOf(normal, projection) > 0;
|
|
298
|
+
const flat = iso(point, projection);
|
|
299
|
+
if (near === null)
|
|
300
|
+
near = facing;
|
|
301
|
+
if (facing !== near) {
|
|
302
|
+
run.push(flat);
|
|
303
|
+
(near ? front : back).push(pathOf(run));
|
|
304
|
+
run = [flat];
|
|
305
|
+
near = facing;
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
run.push(flat);
|
|
309
|
+
}
|
|
310
|
+
if (run.length > 1)
|
|
311
|
+
(near ? front : back).push(pathOf(run));
|
|
312
|
+
return { back: back.join(""), front: front.join("") };
|
|
313
|
+
}
|
|
314
|
+
export function topTicks(from, to, step, every, edge, z, lengths, projection, axis = "x") {
|
|
315
|
+
const minor = [];
|
|
316
|
+
const major = [];
|
|
317
|
+
const first = Math.ceil(from / step) * step;
|
|
318
|
+
for (let at = first, index = Math.round(first / step); at <= to + 1e-9; at += step, index++) {
|
|
319
|
+
const big = index % every === 0;
|
|
320
|
+
const length = big ? lengths[1] : lengths[0];
|
|
321
|
+
const a = axis === "x" ? [at, edge] : [edge, at];
|
|
322
|
+
const b = axis === "x" ? [at, edge + length] : [edge + length, at];
|
|
323
|
+
(big ? major : minor).push(lineOnTop(a, b, z, projection));
|
|
324
|
+
}
|
|
325
|
+
return { minor: minor.join(""), major: major.join("") };
|
|
326
|
+
}
|
|
327
|
+
export function sideTicks(from, to, step, every, face, top, lengths, projection, axis = "x") {
|
|
328
|
+
const minor = [];
|
|
329
|
+
const major = [];
|
|
330
|
+
const first = Math.ceil(from / step) * step;
|
|
331
|
+
for (let at = first, index = Math.round(first / step); at <= to + 1e-9; at += step, index++) {
|
|
332
|
+
const big = index % every === 0;
|
|
333
|
+
const length = big ? lengths[1] : lengths[0];
|
|
334
|
+
const a = axis === "x" ? [at, face, top] : [face, at, top];
|
|
335
|
+
const b = axis === "x" ? [at, face, top - length] : [face, at, top - length];
|
|
336
|
+
(big ? major : minor).push(segment(a, b, projection));
|
|
337
|
+
}
|
|
338
|
+
return { minor: minor.join(""), major: major.join("") };
|
|
339
|
+
}
|
|
340
|
+
export function radialTicks(cx, cy, radius, count, every, z, lengths, projection, from = 0, span = Math.PI * 2) {
|
|
341
|
+
const minor = [];
|
|
342
|
+
const major = [];
|
|
343
|
+
const closed = Math.abs(span - Math.PI * 2) < 1e-9;
|
|
344
|
+
const steps = closed ? count : count + 1;
|
|
345
|
+
for (let index = 0; index < steps; index++) {
|
|
346
|
+
const angle = from + (index / count) * span;
|
|
347
|
+
const big = index % every === 0;
|
|
348
|
+
const inner = radius - (big ? lengths[1] : lengths[0]);
|
|
349
|
+
const sx = Math.sin(angle);
|
|
350
|
+
const sy = -Math.cos(angle);
|
|
351
|
+
(big ? major : minor).push(lineOnTop([cx + sx * inner, cy + sy * inner], [cx + sx * radius, cy + sy * radius], z, projection));
|
|
352
|
+
}
|
|
353
|
+
return { minor: minor.join(""), major: major.join("") };
|
|
354
|
+
}
|
|
355
|
+
export const haloOf = (plan, z, height, projection) => slabOf(plan, z, height, projection).fill;
|
|
356
|
+
export function axisVector(projection, [dx, dy, dz]) {
|
|
357
|
+
const origin = iso([0, 0, 0], projection);
|
|
358
|
+
const moved = iso([dx, dy, dz], projection);
|
|
359
|
+
return [moved[0] - origin[0], moved[1] - origin[1]];
|
|
360
|
+
}
|
|
361
|
+
const fine = (value) => Math.round(value * 100) / 100;
|
|
362
|
+
export function translateAlong(projection, by) {
|
|
363
|
+
const [x, y] = axisVector(projection, by);
|
|
364
|
+
return `translate(${fine(x)} ${fine(y)})`;
|
|
365
|
+
}
|
|
366
|
+
const thousandth = (value) => Math.round(value * 1000) / 1000;
|
|
367
|
+
function axesAt(at, z, projection) {
|
|
368
|
+
const origin = iso([at[0], at[1], z], projection);
|
|
369
|
+
const along = (point) => {
|
|
370
|
+
const [px, py] = iso(point, projection);
|
|
371
|
+
return [px - origin[0], py - origin[1]];
|
|
372
|
+
};
|
|
373
|
+
return { origin, x: along([at[0] + 1, at[1], z]), y: along([at[0], at[1] + 1, z]), z: along([at[0], at[1], z + 1]) };
|
|
374
|
+
}
|
|
375
|
+
const matrixOf = (u, v, origin) => `matrix(${thousandth(u[0])} ${thousandth(u[1])} ${thousandth(v[0])} ${thousandth(v[1])} ${thousandth(origin[0])} ${thousandth(origin[1])})`;
|
|
376
|
+
export function holdStill(element, [dx, dy]) {
|
|
377
|
+
const text = dx || dy ? `translate(${-dx} ${-dy})` : "";
|
|
378
|
+
element.querySelectorAll("[data-hold]").forEach((node) => (text ? node.setAttribute("transform", text) : node.removeAttribute("transform")));
|
|
379
|
+
}
|
|
380
|
+
export function topMatrix(at, z, projection, along = "x") {
|
|
381
|
+
const { origin, x, y } = axesAt(at, z, projection);
|
|
382
|
+
return along === "x" ? matrixOf(x, y, origin) : matrixOf([-y[0], -y[1]], x, origin);
|
|
383
|
+
}
|
|
384
|
+
export function sideMatrix(at, z, projection, face) {
|
|
385
|
+
const { origin, x, y, z: up } = axesAt(at, z, projection);
|
|
386
|
+
const down = [-up[0], -up[1]];
|
|
387
|
+
return face === "left" ? matrixOf(x, down, origin) : matrixOf([-y[0], -y[1]], down, origin);
|
|
388
|
+
}
|
|
389
|
+
export function screenRise(height, projection) {
|
|
390
|
+
const { cosE, k } = cameraOf(projection);
|
|
391
|
+
return height * cosE * k;
|
|
392
|
+
}
|
|
393
|
+
export function fitProjection(points, width, height, { pad = 24, headroom = 0, azimuth = AZIMUTH, elevation = ELEVATION } = {}) {
|
|
394
|
+
const unit = { origin: [0, 0], scale: 1, azimuth, elevation };
|
|
395
|
+
const flat = points.map((point) => iso(point, unit));
|
|
396
|
+
const xs = flat.map(([x]) => x);
|
|
397
|
+
const ys = flat.map(([, y]) => y);
|
|
398
|
+
const left = Math.min(...xs);
|
|
399
|
+
const right = Math.max(...xs);
|
|
400
|
+
const up = Math.min(...ys);
|
|
401
|
+
const down = Math.max(...ys);
|
|
402
|
+
const scale = Math.min((width - pad * 2) / (right - left), (height - pad * 2 - headroom) / (down - up));
|
|
403
|
+
return {
|
|
404
|
+
origin: [width / 2 - ((left + right) / 2) * scale, headroom + (height - headroom) / 2 - ((up + down) / 2) * scale],
|
|
405
|
+
scale,
|
|
406
|
+
azimuth,
|
|
407
|
+
elevation,
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
const escape = (text) => text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
411
|
+
const attrs = (pairs) => Object.entries(pairs)
|
|
412
|
+
.filter(([, value]) => value !== undefined && value !== false)
|
|
413
|
+
.map(([key, value]) => ` ${key}="${escape(String(value))}"`)
|
|
414
|
+
.join("");
|
|
415
|
+
export function solidSvg(paths, { tone = "hi", crease = "faint", halo = false, lit = false, flat = false, className, inner = "" } = {}) {
|
|
416
|
+
const parts = [];
|
|
417
|
+
if (halo)
|
|
418
|
+
parts.push(`<path class="iso-halo" d="${paths.fill}"/>`);
|
|
419
|
+
parts.push(`<path class="iso-fill" d="${paths.fill}"/>`);
|
|
420
|
+
if (!flat) {
|
|
421
|
+
paths.shades.forEach((d, shade) => {
|
|
422
|
+
if (d)
|
|
423
|
+
parts.push(`<path class="iso-shade" data-shade="${shade}" d="${d}"/>`);
|
|
424
|
+
});
|
|
425
|
+
parts.push(`<path class="iso-top" d="${paths.top}"/>`);
|
|
426
|
+
}
|
|
427
|
+
if (crease !== "none" && paths.crease)
|
|
428
|
+
parts.push(`<path class="iso-line iso-crease" data-tone="${crease}" d="${paths.crease}"/>`);
|
|
429
|
+
if (crease !== "none" && paths.bevel)
|
|
430
|
+
parts.push(`<path class="iso-line iso-bevel" data-tone="${crease}" d="${paths.bevel}"/>`);
|
|
431
|
+
if (inner)
|
|
432
|
+
parts.push(inner);
|
|
433
|
+
parts.push(`<path class="iso-line iso-edge" data-tone="${tone}" d="${paths.outline}"/>`);
|
|
434
|
+
return `<g${attrs({ class: className ? `iso-solid ${className}` : "iso-solid", "data-lit": lit ? "" : undefined, "data-seamless": paths.seamless ? "" : undefined })}>${parts.join("")}</g>`;
|
|
435
|
+
}
|
|
436
|
+
export function lineSvg(d, { tone = "lo", dotted = false, dashed = false, flow = false, className, free } = {}) {
|
|
437
|
+
if (!d)
|
|
438
|
+
return "";
|
|
439
|
+
return `<path${attrs({
|
|
440
|
+
class: className ? `iso-line ${className}` : "iso-line",
|
|
441
|
+
"data-tone": tone,
|
|
442
|
+
"data-free": free === true ? "" : free || undefined,
|
|
443
|
+
"data-dotted": dotted ? "" : undefined,
|
|
444
|
+
"data-dashed": dashed ? "" : undefined,
|
|
445
|
+
"data-flow": flow ? "" : undefined,
|
|
446
|
+
d,
|
|
447
|
+
})}/>`;
|
|
448
|
+
}
|
|
449
|
+
export function dotsSvg(points, { size = 0.5, tone = "mid", pulse = false } = {}) {
|
|
450
|
+
const dots = points
|
|
451
|
+
.map(([x, y, alpha], index) => `<circle cx="${tenth(x)}" cy="${tenth(y)}" r="${size}"${alpha !== undefined && alpha < 1 ? ` fill-opacity="${Math.max(0, alpha).toFixed(2)}"` : ""}${pulse ? ` data-pulse="" style="--pulse-at:${(index * 137) % 1600}ms"` : ""}/>`)
|
|
452
|
+
.join("");
|
|
453
|
+
return `<g class="iso-dots" data-tone="${tone}">${dots}</g>`;
|
|
454
|
+
}
|
|
455
|
+
export function fadedSvg(list, style = {}) {
|
|
456
|
+
const groups = new Map();
|
|
457
|
+
for (const entry of list) {
|
|
458
|
+
const [d, alpha] = Array.isArray(entry) ? entry : [entry.d, entry.alpha];
|
|
459
|
+
if (!d || !(alpha > 0.02))
|
|
460
|
+
continue;
|
|
461
|
+
const level = Math.min(1, Math.round(alpha * 20) / 20);
|
|
462
|
+
groups.set(level, (groups.get(level) ?? "") + d);
|
|
463
|
+
}
|
|
464
|
+
return [...groups].map(([alpha, d]) => (alpha >= 1 ? lineSvg(d, style) : `<g opacity="${alpha.toFixed(2)}">${lineSvg(d, style)}</g>`)).join("");
|
|
465
|
+
}
|
|
466
|
+
export function fadeLineSvg(points, { fade = [0, 0], tone = "lo", className, stops = 6 } = {}) {
|
|
467
|
+
if (points.length < 2)
|
|
468
|
+
return "";
|
|
469
|
+
const ease = (t) => t * t * (3 - 2 * t);
|
|
470
|
+
const hashOf = (text) => {
|
|
471
|
+
let hash = 2166136261;
|
|
472
|
+
for (let index = 0; index < text.length; index++)
|
|
473
|
+
hash = Math.imul(hash ^ text.charCodeAt(index), 16777619);
|
|
474
|
+
return (hash >>> 0).toString(36);
|
|
475
|
+
};
|
|
476
|
+
const lengths = [0];
|
|
477
|
+
for (let index = 1; index < points.length; index++)
|
|
478
|
+
lengths.push(lengths[index - 1] + Math.hypot(points[index][0] - points[index - 1][0], points[index][1] - points[index - 1][1]));
|
|
479
|
+
const at = (length) => {
|
|
480
|
+
let index = 1;
|
|
481
|
+
while (index < points.length - 1 && lengths[index] < length)
|
|
482
|
+
index++;
|
|
483
|
+
const span = lengths[index] - lengths[index - 1] || 1;
|
|
484
|
+
const t = Math.max(0, Math.min(1, (length - lengths[index - 1]) / span));
|
|
485
|
+
return [points[index - 1][0] + (points[index][0] - points[index - 1][0]) * t, points[index - 1][1] + (points[index][1] - points[index - 1][1]) * t];
|
|
486
|
+
};
|
|
487
|
+
const pieceOf = (from, to) => [at(from), ...points.filter((_, index) => lengths[index] > from + 1e-6 && lengths[index] < to - 1e-6), at(to)];
|
|
488
|
+
const total = lengths[lengths.length - 1];
|
|
489
|
+
if (total < 1e-6)
|
|
490
|
+
return "";
|
|
491
|
+
let [start, end] = Array.isArray(fade) ? fade : [fade, fade];
|
|
492
|
+
if (start + end > total) {
|
|
493
|
+
const share = total / (start + end);
|
|
494
|
+
start *= share;
|
|
495
|
+
end *= share;
|
|
496
|
+
}
|
|
497
|
+
const paint = `var(--anatomy-${tone})`;
|
|
498
|
+
const ramp = (piece, rising) => {
|
|
499
|
+
const d = pathOf(piece);
|
|
500
|
+
const [x1, y1] = piece[0];
|
|
501
|
+
const [x2, y2] = piece[piece.length - 1];
|
|
502
|
+
const id = `iso-fade-${hashOf(`${d}|${tone}|${rising}`)}`;
|
|
503
|
+
const marks = Array.from({ length: stops + 1 }, (_, index) => {
|
|
504
|
+
const t = index / stops;
|
|
505
|
+
const alpha = ease(rising ? t : 1 - t);
|
|
506
|
+
return `<stop offset="${t.toFixed(3)}" stop-opacity="${alpha.toFixed(3)}" style="stop-color:${paint}"/>`;
|
|
507
|
+
}).join("");
|
|
508
|
+
const gradient = `<linearGradient id="${id}" gradientUnits="userSpaceOnUse" x1="${tenth(x1)}" y1="${tenth(y1)}" x2="${tenth(x2)}" y2="${tenth(y2)}">${marks}</linearGradient>`;
|
|
509
|
+
return `<defs>${gradient}</defs><path${attrs({ class: className ? `iso-line ${className}` : "iso-line", "data-tone": tone, "data-free": rising ? "start" : "end", d, style: `stroke:url(#${id})` })}/>`;
|
|
510
|
+
};
|
|
511
|
+
const parts = [];
|
|
512
|
+
if (start > 0.05)
|
|
513
|
+
parts.push(ramp(pieceOf(0, start), true));
|
|
514
|
+
if (total - end - start > 0.05)
|
|
515
|
+
parts.push(lineSvg(pathOf(pieceOf(start, total - end)), { tone, className }));
|
|
516
|
+
if (end > 0.05)
|
|
517
|
+
parts.push(ramp(pieceOf(total - end, total), false));
|
|
518
|
+
return `<g class="iso-fade">${parts.join("")}</g>`;
|
|
519
|
+
}
|
|
520
|
+
export function wireSvg(from, to, { via = [], tone = "lo", dotted = false, dashed = false, flow = false, ends = "both", size = 1.2 } = {}) {
|
|
521
|
+
const d = pathOf([from, ...via, to]);
|
|
522
|
+
const end = ([x, y]) => `<circle class="iso-wire-end" cx="${tenth(x)}" cy="${tenth(y)}" r="${size}"/>`;
|
|
523
|
+
return `<g class="iso-wire" data-tone="${tone}">${lineSvg(d, { tone, dotted, dashed, flow })}${ends === "both" || ends === "from" ? end(from) : ""}${ends === "both" || ends === "to" ? end(to) : ""}</g>`;
|
|
524
|
+
}
|
|
525
|
+
export function faceTextSvg(transform, text, { size = 3, tone = "mid", anchor = "start" } = {}) {
|
|
526
|
+
return `<text class="iso-face-text" data-tone="${tone}" transform="${transform}" font-size="${size}" text-anchor="${anchor}">${escape(text)}</text>`;
|
|
527
|
+
}
|
|
528
|
+
export function groupSvg(children, extra = {}) {
|
|
529
|
+
return `<g${attrs(extra)}>${Array.isArray(children) ? children.join("") : children}</g>`;
|
|
530
|
+
}
|
|
531
|
+
export function figureSvg({ width, height, label, body, standalone = false, className }) {
|
|
532
|
+
const style = standalone ? `<style>${ISO_CSS}</style>` : "";
|
|
533
|
+
return `<svg${attrs({
|
|
534
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
535
|
+
class: `iso-svg${standalone ? " iso" : ""}${className ? ` ${className}` : ""}`,
|
|
536
|
+
"data-theme": standalone || undefined,
|
|
537
|
+
viewBox: `0 0 ${width} ${height}`,
|
|
538
|
+
role: "img",
|
|
539
|
+
"aria-label": label,
|
|
540
|
+
})}>${style}${Array.isArray(body) ? body.join("") : body}</svg>`;
|
|
541
|
+
}
|
|
542
|
+
function swatchSvg(mark) {
|
|
543
|
+
if (mark === "raised" || mark === "flat" || mark === "lit") {
|
|
544
|
+
const body = mark === "flat" ? "M2 6.5 8 3.5 14 6.5 8 9.5Z" : "M2 4.5 8 1.5 14 4.5 14 6 8 9 2 6Z";
|
|
545
|
+
const crease = mark === "flat" ? "" : `<path class="iso-swatch-crease" d="M2 4.5 8 7.5 14 4.5"/>`;
|
|
546
|
+
return `<svg class="iso-swatch" data-mark="${mark}" viewBox="0 0 16 10" aria-hidden="true"><path d="${body}"/>${crease}</svg>`;
|
|
547
|
+
}
|
|
548
|
+
return `<svg class="iso-swatch" data-mark="${mark}" viewBox="0 0 16 10" aria-hidden="true"><path d="M1.5 5h13"/></svg>`;
|
|
549
|
+
}
|
|
550
|
+
export function plateHtml({ fig, title, hint, readout = "", keys = [], caption, body }) {
|
|
551
|
+
const corner = (name, text, extra = "") => `<span class="iso-plate-corner" data-corner="${name}"${extra}>${escape(text)}</span>`;
|
|
552
|
+
const legend = keys.length || caption
|
|
553
|
+
? `<figcaption class="iso-legend">${keys.length ? `<span class="iso-keys">${keys.map((key) => `<span class="iso-key">${swatchSvg(key.mark)}${escape(key.label)}</span>`).join("")}</span>` : ""}${caption ? `<span class="iso-caption">${escape(caption)}</span>` : ""}</figcaption>`
|
|
554
|
+
: "";
|
|
555
|
+
return `<figure class="iso-figure"><div class="iso-plate"><div class="iso-plate-corners" aria-hidden="true">${corner("fig", fig)}${title ? corner("title", title) : ""}${hint ? corner("hint", hint) : ""}${corner("readout", readout, " data-readout")}</div>${body}</div>${legend}</figure>`;
|
|
556
|
+
}
|
|
557
|
+
export function pageHtml({ title, theme = "dark", body, script = "", width = 650 }) {
|
|
558
|
+
return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>${escape(title)}</title><style>${ISO_CSS}${PAGE_CSS.replace("__WIDTH__", String(width))}</style></head><body class="iso" data-theme="${theme}"><main class="iso-page">${body}</main>${script ? `<script type="module">${script.replace(/<\/(script)/gi, "<\\/$1")}</script>` : ""}</body></html>`;
|
|
559
|
+
}
|
|
560
|
+
const PAGE_CSS = `
|
|
561
|
+
*{box-sizing:border-box}
|
|
562
|
+
html{color-scheme:dark}
|
|
563
|
+
body[data-theme="light"]{color-scheme:light}
|
|
564
|
+
body{margin:0;background:var(--anatomy-page);color:var(--anatomy-text);font:14px/1.6 ui-sans-serif,system-ui,-apple-system,"Segoe UI",sans-serif;-webkit-font-smoothing:antialiased}
|
|
565
|
+
.iso-page{width:min(__WIDTH__px,100% - 32px);margin:64px auto 96px}
|
|
566
|
+
`;
|
|
567
|
+
export const ISO_CSS = `
|
|
568
|
+
.iso{
|
|
569
|
+
--anatomy-page:#0b0b0b;--anatomy-card:#131313;--anatomy-text:#a3a3a3;--anatomy-strong:#e6e6e6;--anatomy-muted:#6e6e6e;
|
|
570
|
+
--anatomy-paper:#131313;--anatomy-face:#1b1b1b;--anatomy-top:#1c1c1c;
|
|
571
|
+
--anatomy-shade-0:#0f0f0f;--anatomy-shade-1:#121212;--anatomy-shade-2:#151515;--anatomy-shade-3:#181818;
|
|
572
|
+
--anatomy-lit-top:#262626;--anatomy-lit-shade:#1d1d1d;
|
|
573
|
+
--anatomy-hi:#d4d4d4;--anatomy-mid:#6a6a6a;--anatomy-lo:#3e3e3e;--anatomy-faint:#2a2a2a;--anatomy-lit:#ffffff;
|
|
574
|
+
--anatomy-halo:#050505;--anatomy-halo-opacity:.9;--anatomy-dot:#e6e6e6;
|
|
575
|
+
--anatomy-red:#ff6b6b;--anatomy-green:#6be0a0;--anatomy-blue:#6b9bff;
|
|
576
|
+
--anatomy-weight:.6px;--anatomy-ease:cubic-bezier(.32,.72,0,1);
|
|
577
|
+
--anatomy-mono:ui-monospace,"SF Mono",Menlo,Consolas,monospace;
|
|
578
|
+
--anatomy-lift:inset 0 1px 0 0 #ffffff0a,inset 0 0 0 1px #ffffff06,0 0 0 1px #00000026,0 1px 1px -.5px #00000014,0 3px 3px -1.5px #00000014,0 6px 6px -3px #00000014,0 12px 12px -6px #00000014;
|
|
579
|
+
}
|
|
580
|
+
.iso[data-theme="light"]{
|
|
581
|
+
--anatomy-page:#f2f2ef;--anatomy-card:#fbfbfa;--anatomy-text:#57575a;--anatomy-strong:#18181a;--anatomy-muted:#8c8c90;
|
|
582
|
+
--anatomy-paper:#fbfbfa;--anatomy-face:#ffffff;--anatomy-top:#ffffff;
|
|
583
|
+
--anatomy-shade-0:#dcdcd9;--anatomy-shade-1:#e5e5e2;--anatomy-shade-2:#ededea;--anatomy-shade-3:#f4f4f1;
|
|
584
|
+
--anatomy-lit-top:#ffffff;--anatomy-lit-shade:#eeeeeb;
|
|
585
|
+
--anatomy-hi:#26262a;--anatomy-mid:#8a8a8f;--anatomy-lo:#b4b4b8;--anatomy-faint:#d4d4d6;--anatomy-lit:#000000;
|
|
586
|
+
--anatomy-halo:#8a8a80;--anatomy-halo-opacity:.32;--anatomy-dot:#3a3a3e;
|
|
587
|
+
--anatomy-red:#e5484d;--anatomy-green:#30a46c;--anatomy-blue:#3e63dd;
|
|
588
|
+
--anatomy-lift:inset 0 1px 0 0 #ffffff,0 0 0 1px #0000000f,0 1px 1px -.5px #0000000a,0 3px 3px -1.5px #0000000a,0 6px 6px -3px #0000000a,0 12px 12px -6px #0000000a;
|
|
589
|
+
}
|
|
590
|
+
.iso-svg{display:block;width:100%;height:auto;overflow:visible}
|
|
591
|
+
.iso-svg path,.iso-svg circle{vector-effect:non-scaling-stroke}
|
|
592
|
+
.iso-fill{fill:var(--anatomy-paper);stroke:none}
|
|
593
|
+
.iso-solid[data-lit]>.iso-fill{fill:var(--anatomy-face)}
|
|
594
|
+
.iso-shade,.iso-top{stroke:none}
|
|
595
|
+
.iso-shade[data-shade="0"]{fill:var(--anatomy-shade-0)}
|
|
596
|
+
.iso-shade[data-shade="1"]{fill:var(--anatomy-shade-1)}
|
|
597
|
+
.iso-shade[data-shade="2"]{fill:var(--anatomy-shade-2)}
|
|
598
|
+
.iso-shade[data-shade="3"]{fill:var(--anatomy-shade-3)}
|
|
599
|
+
.iso-top{fill:var(--anatomy-top)}
|
|
600
|
+
.iso-solid[data-lit]>.iso-top{fill:var(--anatomy-lit-top)}
|
|
601
|
+
.iso-solid[data-lit]>.iso-shade{fill:var(--anatomy-lit-shade)}
|
|
602
|
+
.iso-solid[data-seamless]>.iso-shade,.iso-solid[data-seamless]>.iso-top{stroke-width:.4;stroke-linejoin:round}
|
|
603
|
+
.iso-solid[data-seamless]>.iso-shade[data-shade="0"]{stroke:var(--anatomy-shade-0)}
|
|
604
|
+
.iso-solid[data-seamless]>.iso-shade[data-shade="1"]{stroke:var(--anatomy-shade-1)}
|
|
605
|
+
.iso-solid[data-seamless]>.iso-shade[data-shade="2"]{stroke:var(--anatomy-shade-2)}
|
|
606
|
+
.iso-solid[data-seamless]>.iso-shade[data-shade="3"]{stroke:var(--anatomy-shade-3)}
|
|
607
|
+
.iso-solid[data-seamless]>.iso-top{stroke:var(--anatomy-top)}
|
|
608
|
+
.iso-solid[data-seamless][data-lit]>.iso-top{stroke:var(--anatomy-lit-top)}
|
|
609
|
+
.iso-solid[data-seamless][data-lit]>.iso-shade{stroke:var(--anatomy-lit-shade)}
|
|
610
|
+
.iso-solid[data-lit]>.iso-edge{stroke:var(--anatomy-lit)}
|
|
611
|
+
.iso-halo{fill:var(--anatomy-halo);stroke:none;filter:blur(9px);opacity:var(--anatomy-halo-opacity);transform:translateY(3px)}
|
|
612
|
+
.iso-line{fill:none;stroke:var(--anatomy-lo);stroke-width:var(--anatomy-weight);stroke-linecap:round;stroke-linejoin:round}
|
|
613
|
+
.iso-line[data-tone="hi"]{stroke:var(--anatomy-hi)}
|
|
614
|
+
.iso-line[data-tone="mid"]{stroke:var(--anatomy-mid)}
|
|
615
|
+
.iso-line[data-tone="lo"]{stroke:var(--anatomy-lo)}
|
|
616
|
+
.iso-line[data-tone="faint"]{stroke:var(--anatomy-faint)}
|
|
617
|
+
.iso-line[data-tone="lit"]{stroke:var(--anatomy-lit)}
|
|
618
|
+
.iso-line[data-tone="red"]{stroke:var(--anatomy-red)}
|
|
619
|
+
.iso-line[data-tone="green"]{stroke:var(--anatomy-green)}
|
|
620
|
+
.iso-line[data-tone="blue"]{stroke:var(--anatomy-blue)}
|
|
621
|
+
.iso-line[data-dotted]{stroke-dasharray:.01 3.5;stroke-width:1}
|
|
622
|
+
.iso-line[data-dashed]{stroke-dasharray:3 3}
|
|
623
|
+
.iso-line[data-flow]{stroke-dasharray:2 6}
|
|
624
|
+
.iso-wire-end{fill:var(--anatomy-paper);stroke:var(--anatomy-lo);stroke-width:var(--anatomy-weight)}
|
|
625
|
+
.iso-wire[data-tone="hi"] .iso-wire-end{stroke:var(--anatomy-hi)}
|
|
626
|
+
.iso-wire[data-tone="mid"] .iso-wire-end{stroke:var(--anatomy-mid)}
|
|
627
|
+
.iso-wire[data-tone="faint"] .iso-wire-end{stroke:var(--anatomy-faint)}
|
|
628
|
+
.iso-wire[data-tone="lit"] .iso-wire-end{stroke:var(--anatomy-lit)}
|
|
629
|
+
.iso-dots circle{fill:var(--anatomy-dot);stroke:none;opacity:.32}
|
|
630
|
+
.iso-dots[data-tone="hi"] circle{opacity:.85}
|
|
631
|
+
.iso-dots[data-tone="mid"] circle{opacity:.45}
|
|
632
|
+
.iso-dots[data-tone="lo"] circle{opacity:.22}
|
|
633
|
+
.iso-dots[data-tone="faint"] circle{opacity:.12}
|
|
634
|
+
.iso-face-text{fill:var(--anatomy-mid);font-family:var(--anatomy-mono);letter-spacing:.04em}
|
|
635
|
+
.iso-face-text[data-tone="hi"]{fill:var(--anatomy-hi)}
|
|
636
|
+
.iso-face-text[data-tone="lo"]{fill:var(--anatomy-lo)}
|
|
637
|
+
.iso-face-text[data-tone="faint"]{fill:var(--anatomy-faint)}
|
|
638
|
+
.tb-body{fill:var(--anatomy-shade-2);stroke:none}
|
|
639
|
+
.tb-shine{fill:var(--anatomy-top);stroke:none}
|
|
640
|
+
.tb-shade{fill:var(--anatomy-shade-0);stroke:none}
|
|
641
|
+
.tb-ring{fill:none;stroke:var(--anatomy-lo);stroke-width:.45;stroke-linecap:butt;stroke-linejoin:round}
|
|
642
|
+
.tb-ring[data-tone="mid"]{stroke:var(--anatomy-mid)}
|
|
643
|
+
.tb-ring[data-tone="faint"]{stroke:var(--anatomy-faint)}
|
|
644
|
+
.tb-ring[data-tone="hi"]{stroke:var(--anatomy-hi)}
|
|
645
|
+
@keyframes iso-flow{to{stroke-dashoffset:-32}}
|
|
646
|
+
@keyframes iso-pulse{0%,100%{opacity:.18}12%{opacity:1}40%{opacity:.18}}
|
|
647
|
+
.iso-line[data-flow]{animation:iso-flow 1600ms linear infinite}
|
|
648
|
+
.iso-dots circle[data-pulse]{animation:iso-pulse 1600ms steps(1,end) infinite;animation-delay:var(--pulse-at,0ms)}
|
|
649
|
+
.iso-figure{margin:32px 0 36px}
|
|
650
|
+
.iso-plate{position:relative;padding:52px 24px;border-radius:0;background:var(--anatomy-card);box-shadow:0 0 0 1px var(--anatomy-mid);--anatomy-paper:var(--anatomy-card)}
|
|
651
|
+
.iso-plate-corners{position:absolute;inset:18px 20px;pointer-events:none}
|
|
652
|
+
.iso-plate-corner{position:absolute;color:var(--anatomy-muted);font-family:var(--anatomy-mono);font-size:10.5px;line-height:1;letter-spacing:.04em;white-space:nowrap}
|
|
653
|
+
.iso-plate-corner[data-corner="fig"]{top:0;left:0;color:var(--anatomy-text)}
|
|
654
|
+
.iso-plate-corner[data-corner="title"]{top:0;right:0;text-transform:uppercase;letter-spacing:.1em}
|
|
655
|
+
.iso-plate-corner[data-corner="hint"]{bottom:0;left:0;text-transform:uppercase;letter-spacing:.1em}
|
|
656
|
+
.iso-plate-corner[data-corner="readout"]{right:0;bottom:0;color:var(--anatomy-text);font-variant-numeric:tabular-nums}
|
|
657
|
+
.iso-plate .iso-svg{margin:0 auto}
|
|
658
|
+
.iso-legend{display:grid;gap:8px;margin-top:12px;color:var(--anatomy-muted);font-size:13px;line-height:1.55}
|
|
659
|
+
.iso-keys{display:flex;flex-wrap:wrap;gap:6px 18px}
|
|
660
|
+
.iso-key{display:inline-flex;align-items:center;gap:7px}
|
|
661
|
+
.iso-swatch{width:16px;height:10px;flex:none;overflow:visible}
|
|
662
|
+
.iso-swatch path{fill:none;stroke:var(--anatomy-hi);stroke-width:1;vector-effect:non-scaling-stroke;stroke-linejoin:round;stroke-linecap:round}
|
|
663
|
+
.iso-swatch[data-mark="raised"] path,.iso-swatch[data-mark="flat"] path{stroke:var(--anatomy-mid)}
|
|
664
|
+
.iso-swatch[data-mark="lit"] path{stroke:var(--anatomy-lit)}
|
|
665
|
+
.iso-swatch[data-mark="dim"] path{stroke:var(--anatomy-lo)}
|
|
666
|
+
.iso-swatch[data-mark="dotted"] path{stroke-dasharray:.01 3;stroke-width:1.4}
|
|
667
|
+
.iso-swatch[data-mark="dashed"] path{stroke-dasharray:3 2.5}
|
|
668
|
+
.iso-swatch[data-mark="red"] path{stroke:var(--anatomy-red)}
|
|
669
|
+
.iso-swatch[data-mark="green"] path{stroke:var(--anatomy-green)}
|
|
670
|
+
.iso-swatch[data-mark="blue"] path{stroke:var(--anatomy-blue)}
|
|
671
|
+
.iso-swatch-crease{stroke:var(--anatomy-lo)!important}
|
|
672
|
+
@media (max-width:560px){.iso-plate{padding:48px 12px 70px}.iso-plate-corner[data-corner="hint"]{bottom:18px}}
|
|
673
|
+
@media (prefers-reduced-motion:reduce){.iso-line[data-flow],.iso-dots circle[data-pulse]{animation:none}}
|
|
674
|
+
`;
|
package/dist/viewer.html
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<section id="atlas-review" aria-label="DeVibe, explorador de código local">
|
|
2
2
|
<header class="ar-bar">
|
|
3
|
-
<div class="ar-brand"><span class="ar-mark" aria-hidden="true"
|
|
3
|
+
<div class="ar-brand"><span class="ar-mark" aria-hidden="true">D</span><strong>DeVibe</strong></div>
|
|
4
4
|
<div class="ar-project"><span data-case-project>Proyecto</span><span aria-hidden="true">/</span><span data-case-area>Recorrido</span></div>
|
|
5
5
|
<span class="ar-local"><i data-lucide="hard-drive" aria-hidden="true"></i> <span data-case-environment></span></span>
|
|
6
6
|
<label class="ar-preference">Tema <select data-ui-theme aria-label="Tema de la interfaz"><option value="auto">Sistema</option><option value="light">Claro</option><option value="dark">Oscuro</option></select></label>
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
<h3 id="ar-flow-title">Recorrido</h3>
|
|
28
28
|
<div class="ar-layout" role="group" aria-label="Vista del recorrido">
|
|
29
29
|
<button type="button" data-layout="iso" aria-pressed="true">Isométrico</button>
|
|
30
|
+
<button type="button" data-layout="anatomy" aria-pressed="false" hidden>Anatomy</button>
|
|
30
31
|
<button type="button" data-layout="steps" aria-pressed="false">Pasos</button>
|
|
31
32
|
</div>
|
|
32
33
|
</div>
|
|
@@ -58,6 +59,19 @@
|
|
|
58
59
|
</div>
|
|
59
60
|
<div class="ar-detail-list" hidden></div>
|
|
60
61
|
</div>
|
|
62
|
+
<section class="ar-anatomy" aria-label="Mapa de llamadas" hidden>
|
|
63
|
+
<header><p>El trazo discontinuo indica una conexión inferida o sin clasificar.<span data-cycle-note hidden> La flecha curva señala un ciclo de llamadas.</span></p>
|
|
64
|
+
<label hidden>Cámara <select data-graph-camera><option value="diagonal">Diagonal</option><option value="opposite">Lado opuesto</option><option value="high">Elevada</option></select></label>
|
|
65
|
+
</header>
|
|
66
|
+
<p class="ar-anatomy-status" role="status"></p>
|
|
67
|
+
<div class="ar-anatomy-scroll" tabindex="0" role="region" aria-label="Mapa de llamadas desplazable">
|
|
68
|
+
<div class="ar-anatomy-stage">
|
|
69
|
+
<svg aria-hidden="true" focusable="false"></svg>
|
|
70
|
+
<div class="ar-anatomy-pins"></div>
|
|
71
|
+
</div>
|
|
72
|
+
</div>
|
|
73
|
+
<label class="ar-anatomy-picker">Conexión <select data-anatomy-select></select></label>
|
|
74
|
+
</section>
|
|
61
75
|
<ol class="ar-steps" hidden></ol>
|
|
62
76
|
</section>
|
|
63
77
|
<aside class="ar-inspector" aria-labelledby="ar-inspector-title">
|
|
@@ -121,21 +135,42 @@
|
|
|
121
135
|
#atlas-review button:focus-visible { outline: 2px solid var(--ar-green); outline-offset: 2px; }
|
|
122
136
|
#atlas-review :is(svg.lucide,i[data-lucide]) { width: 16px; height: 16px; flex: none; }
|
|
123
137
|
#atlas-review code { font: 12px/1.55 var(--ar-mono); overflow-wrap: anywhere; }
|
|
138
|
+
#atlas-review select {
|
|
139
|
+
appearance: none;
|
|
140
|
+
min-height: 34px;
|
|
141
|
+
max-width: 100%;
|
|
142
|
+
padding: 6px 30px 6px 10px;
|
|
143
|
+
border: 1px solid var(--ar-line);
|
|
144
|
+
border-radius: 8px;
|
|
145
|
+
background-color: var(--ar-paper);
|
|
146
|
+
background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
|
|
147
|
+
background-position: calc(100% - 15px) calc(50% - 2px), calc(100% - 10px) calc(50% - 2px);
|
|
148
|
+
background-size: 5px 5px;
|
|
149
|
+
background-repeat: no-repeat;
|
|
150
|
+
color: var(--ar-ink);
|
|
151
|
+
font: inherit;
|
|
152
|
+
line-height: 1.4;
|
|
153
|
+
transition: border-color .15s ease, background-color .15s ease;
|
|
154
|
+
}
|
|
155
|
+
#atlas-review select:hover { border-color: color-mix(in srgb, var(--ar-green) 55%, var(--ar-line)); }
|
|
156
|
+
#atlas-review select:focus-visible { outline: 2px solid var(--ar-green); outline-offset: 2px; }
|
|
157
|
+
#atlas-review select:disabled { opacity: .55; cursor: progress; }
|
|
158
|
+
#atlas-review select option { background: var(--ar-paper); color: var(--ar-ink); }
|
|
124
159
|
#atlas-review .ar-bar { min-height: 58px; padding: 9px 23px; display: flex; align-items: center; flex-wrap: wrap; gap: 8px 18px; background: var(--ar-paper); border-bottom: 1px solid var(--ar-line); }
|
|
125
160
|
#atlas-review :is(.ar-brand,.ar-project,.ar-local,.ar-revision) { display: inline-flex; align-items: center; gap: 8px; }
|
|
126
161
|
#atlas-review .ar-brand strong { font-size: 19px; letter-spacing: -.04em; }
|
|
127
|
-
#atlas-review .ar-mark { display: grid; place-items: center; width: 29px; height: 29px; border-radius: 7px; background: var(--ar-selection); color: var(--ar-green); }
|
|
162
|
+
#atlas-review .ar-mark { display: grid; place-items: center; width: 29px; height: 29px; border-radius: 7px; background: var(--ar-selection); color: var(--ar-green); font-weight: 800; }
|
|
128
163
|
#atlas-review .ar-project { color: var(--ar-sub); font-size: 13px; flex-wrap: wrap; }
|
|
129
164
|
#atlas-review .ar-local { margin-inline-start: auto; color: var(--ar-sub); font-size: 12px; }
|
|
130
165
|
#atlas-review .ar-preference { display: flex; align-items: center; gap: 6px; color: var(--ar-sub); font-size: 12px; }
|
|
131
|
-
#atlas-review .ar-preference select { min-height: 32px;
|
|
166
|
+
#atlas-review .ar-preference select { min-height: 32px; padding: 4px 28px 4px 9px; font-size: 12px; }
|
|
132
167
|
#atlas-review .ar-main { padding: 22px 23px; }
|
|
133
168
|
#atlas-review .ar-heading { display: flex; align-items: end; justify-content: space-between; flex-wrap: wrap; gap: 8px 16px; }
|
|
134
169
|
#atlas-review .ar-heading h2 { font: 500 clamp(25px,4.4cqi,41px)/1.08 Georgia,serif; letter-spacing: -.045em; }
|
|
135
170
|
#atlas-review .ar-heading p { margin-top: 7px; color: var(--ar-sub); }
|
|
136
171
|
#atlas-review .ar-revision { color: var(--ar-sub); }
|
|
137
172
|
#atlas-review .ar-entry { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 12px; }
|
|
138
|
-
#atlas-review :is(.ar-entry,.ar-changed-files) select {
|
|
173
|
+
#atlas-review :is(.ar-entry,.ar-changed-files) select { font-size: 13px; }
|
|
139
174
|
#atlas-review .ar-entry span { color: var(--ar-sub); font-size: 12px; }
|
|
140
175
|
#atlas-review .ar-nav { display: flex; flex-wrap: wrap; align-items: end; gap: 15px; margin: 15px 0 14px; border-bottom: 1px solid var(--ar-line); }
|
|
141
176
|
#atlas-review .ar-nav button { padding: 0 2px; min-height: 44px; border: 0; border-bottom: 2px solid transparent; font-weight: 550; color: var(--ar-sub); background: transparent; }
|
|
@@ -179,7 +214,8 @@
|
|
|
179
214
|
#atlas-review .ar-change { font-size: 11px; font-weight: 630; color: var(--ar-green); }
|
|
180
215
|
#atlas-review .ar-map-tools { position: relative; display: flex; flex-wrap: wrap; align-items: end; gap: 8px; padding: 9px 12px; border-bottom: 1px solid var(--ar-line); }
|
|
181
216
|
#atlas-review .ar-map-tools > label { display: grid; gap: 2px; min-width: 0; color: var(--ar-sub); font-size: 11px; }
|
|
182
|
-
#atlas-review .ar-map-tools
|
|
217
|
+
#atlas-review .ar-map-tools select { font-size: 12px; }
|
|
218
|
+
#atlas-review .ar-map-tools summary { min-height: 33px; max-width: 100%; padding: 4px 6px; border: 1px solid var(--ar-line); border-radius: 6px; background: var(--ar-paper); color: var(--ar-ink); font: 12px/1.4 'Aptos','Segoe UI',sans-serif; }
|
|
183
219
|
#atlas-review .ar-filters { font-size: 12px; }
|
|
184
220
|
#atlas-review .ar-filters summary { align-content: center; cursor: pointer; }
|
|
185
221
|
#atlas-review .ar-filters fieldset { position: absolute; z-index: 2; inset-inline-end: 12px; inset-block-start: calc(100% - 4px); display: grid; min-width: 139px; margin: 0; padding: 5px 9px; border: 1px solid var(--ar-line); border-radius: 7px; background: var(--ar-paper); box-shadow: 0 9px 20px color-mix(in srgb,var(--ar-ink) 13%,transparent); }
|
|
@@ -187,6 +223,42 @@
|
|
|
187
223
|
#atlas-review .ar-filters input { accent-color: var(--ar-green); }
|
|
188
224
|
#atlas-review .ar-scene { position: relative; aspect-ratio: 420 / 292; background: var(--ar-map-ground); }
|
|
189
225
|
#atlas-review .ar-world, #atlas-review .ar-pins { display: block; position: absolute; inset: 0; width: 100%; height: 100%; }
|
|
226
|
+
#atlas-review .ar-anatomy { min-width: 0; color: var(--ar-ink); }
|
|
227
|
+
#atlas-review .ar-anatomy header { padding: 8px 12px; border-bottom: 1px solid var(--ar-line); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
|
|
228
|
+
#atlas-review .ar-anatomy header label { display: flex; align-items: center; gap: 4px; color: var(--ar-sub); font-size: 12px; }
|
|
229
|
+
#atlas-review .ar-anatomy p { margin: 0; color: var(--ar-sub); font-size: 12px; }
|
|
230
|
+
#atlas-review .ar-anatomy-status:not(:empty) { padding: 12px 14px; }
|
|
231
|
+
#atlas-review .ar-anatomy-scroll { overflow: auto; background: var(--ar-map-ground); }
|
|
232
|
+
#atlas-review .ar-anatomy-stage { min-width: 520px; position: relative; }
|
|
233
|
+
#atlas-review .ar-anatomy-stage[data-graph-view="anatomy"] { background: radial-gradient(circle, var(--ar-line) 1px, transparent 1px) 0 0 / 20px 20px, var(--ar-paper); }
|
|
234
|
+
#atlas-review .ar-anatomy-stage[data-graph-view="iso"] .ar-floor { fill: var(--ar-map-ground); }
|
|
235
|
+
#atlas-review .ar-anatomy-stage svg, #atlas-review .ar-anatomy-pins { position: absolute; inset: 0; width: 100%; height: 100%; }
|
|
236
|
+
#atlas-review .ar-anatomy-pins { pointer-events: none; }
|
|
237
|
+
#atlas-review .ar-anatomy-pins button { position: absolute; translate: -50% 0; pointer-events: auto; display: grid; min-width: 80px; max-width: 132px; padding: 4px 8px; border: 1px solid var(--ar-line); border-radius: 5px; background: var(--ar-paper); color: var(--ar-ink); }
|
|
238
|
+
#atlas-review .ar-anatomy-pins strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 620 12px var(--ar-mono); }
|
|
239
|
+
#atlas-review .ar-anatomy-pins small { color: var(--ar-sub); font-size: 11px; line-height: 1.3; }
|
|
240
|
+
#atlas-review .ar-anatomy-pins button[data-anatomy-root] { border-color: var(--ar-map-line); }
|
|
241
|
+
#atlas-review .ar-anatomy-pins button[data-active] { background: var(--ar-selection); border-color: var(--ar-green); }
|
|
242
|
+
#atlas-review .ar-anatomy-wire { fill: none; stroke: var(--ar-map-line); stroke-width: 1.5; stroke-linejoin: round; }
|
|
243
|
+
#atlas-review .ar-anatomy-uncertain .ar-anatomy-wire { stroke-dasharray: 4 4; }
|
|
244
|
+
#atlas-review .ar-anatomy-edge[data-active] .ar-anatomy-wire, #atlas-review .ar-anatomy-edge:hover .ar-anatomy-wire { stroke: var(--ar-green); stroke-width: 2.5; }
|
|
245
|
+
#atlas-review .ar-anatomy-hit { fill: none; stroke: transparent; stroke-width: 12; cursor: pointer; }
|
|
246
|
+
#atlas-review .ar-anatomy-cycle .ar-anatomy-wire { stroke: var(--ar-amber); }
|
|
247
|
+
#atlas-review .ar-anatomy-object { pointer-events: none; --ar-piece: light-dark(#b8c3b0,#435348); --ar-piece-top: light-dark(#e1e9d8,#65746a); }
|
|
248
|
+
#atlas-review .ar-anatomy-object[data-kind="function"] { --ar-piece: light-dark(#afc584,#4e6540); --ar-piece-top: light-dark(#e0eab6,#82975f); }
|
|
249
|
+
#atlas-review .ar-anatomy-object:is([data-kind="method"],[data-kind="class"]) { --ar-piece: light-dark(#91aeb8,#405e68); --ar-piece-top: light-dark(#c6dde2,#6a8c96); }
|
|
250
|
+
#atlas-review .ar-anatomy-object[data-kind="database"] { --ar-piece: light-dark(#c6a879,#6e543c); --ar-piece-top: light-dark(#eddbad,#9c8057); }
|
|
251
|
+
#atlas-review .ar-anatomy-object[data-kind="network"] { --ar-piece: light-dark(#b2a7c6,#5f4d72); --ar-piece-top: light-dark(#dfd5eb,#8f78a6); }
|
|
252
|
+
#atlas-review .ar-anatomy-glyph circle { fill: var(--ar-paper); stroke: var(--ar-line); }
|
|
253
|
+
#atlas-review .ar-anatomy-glyph path { fill: none; stroke: var(--ar-ink); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
|
|
254
|
+
#atlas-review .ar-anatomy-stage .iso-fill { fill: var(--ar-piece); }
|
|
255
|
+
#atlas-review .ar-anatomy-stage .iso-top { fill: var(--ar-piece-top); }
|
|
256
|
+
#atlas-review .ar-anatomy-stage .iso-shade { fill: black; opacity: .07; }
|
|
257
|
+
#atlas-review .ar-anatomy-stage .iso-shade[data-shade="2"] { opacity: .18; }
|
|
258
|
+
#atlas-review .ar-anatomy-stage .iso-line { fill: none; stroke: var(--ar-map-line); stroke-width: .85; }
|
|
259
|
+
#atlas-review .ar-anatomy-stage .iso-bevel { stroke: var(--ar-piece-top); }
|
|
260
|
+
#atlas-review .ar-anatomy-picker { display: flex; align-items: center; gap: 8px; border-top: 1px solid var(--ar-line); padding: 10px 14px; font-size: 13px; }
|
|
261
|
+
#atlas-review .ar-anatomy-picker select { min-width: 0; max-width: 100%; }
|
|
190
262
|
#atlas-review .ar-pins { pointer-events: none; }
|
|
191
263
|
#atlas-review .ar-pin { position: absolute; display: grid; justify-items: center; width: max-content; min-width: 60px; max-width: 32%; transform: translate(-50%,-50%); padding: 4px 6px; text-align: center; border: 1px solid var(--ar-line); border-radius: 6px; background: var(--ar-paper); pointer-events: auto; }
|
|
192
264
|
#atlas-review .ar-pin strong { font-size: 12px; line-height: 1.15; }
|
|
@@ -261,6 +333,17 @@
|
|
|
261
333
|
const context = root.querySelector('.ar-context');
|
|
262
334
|
const revision = root.querySelector('.ar-revision code');
|
|
263
335
|
const map = root.querySelector('.ar-map');
|
|
336
|
+
const anatomy = root.querySelector('.ar-anatomy');
|
|
337
|
+
const anatomyStage = anatomy.querySelector('.ar-anatomy-stage');
|
|
338
|
+
const anatomyStatus = anatomy.querySelector('.ar-anatomy-status');
|
|
339
|
+
const anatomySelect = anatomy.querySelector('[data-anatomy-select]');
|
|
340
|
+
const graphCamera = anatomy.querySelector('[data-graph-camera]');
|
|
341
|
+
const cycleNote = anatomy.querySelector('[data-cycle-note]');
|
|
342
|
+
let anatomyModule;
|
|
343
|
+
let anatomyFlow;
|
|
344
|
+
let anatomyView;
|
|
345
|
+
let anatomyCamera;
|
|
346
|
+
let anatomyRequest = 0;
|
|
264
347
|
const world = map.querySelector('.ar-world');
|
|
265
348
|
const pins = map.querySelector('.ar-pins');
|
|
266
349
|
const detailList = map.querySelector('.ar-detail-list');
|
|
@@ -303,7 +386,8 @@
|
|
|
303
386
|
map.querySelector('.ar-map-return').textContent = atlasCase.labels.response;
|
|
304
387
|
}
|
|
305
388
|
if (graphProject) {
|
|
306
|
-
root.querySelector('
|
|
389
|
+
root.querySelector('[data-layout="iso"]').hidden = graphProject.entries.length === 0;
|
|
390
|
+
root.querySelector('[data-layout="anatomy"]').hidden = graphProject.entries.length === 0;
|
|
307
391
|
root.querySelector('#ar-flow-title').textContent = 'Llamadas detectadas';
|
|
308
392
|
steps.setAttribute('data-static', '');
|
|
309
393
|
root.querySelector('.ar-entry').hidden = graphProject.entries.length === 0;
|
|
@@ -326,7 +410,7 @@
|
|
|
326
410
|
const { error: errorBranch, details } = atlasCase;
|
|
327
411
|
const catalogue = new Map(Object.values(details).flat().map(entry => [entry.id, entry]));
|
|
328
412
|
let mode = 'learn';
|
|
329
|
-
let layout = graphProject ? 'steps' : 'iso';
|
|
413
|
+
let layout = graphProject && !graphProject.entries.length ? 'steps' : 'iso';
|
|
330
414
|
let selected = graphProject ? 0 : 1;
|
|
331
415
|
let selectedDetail = null;
|
|
332
416
|
let detail = 'module';
|
|
@@ -533,13 +617,55 @@
|
|
|
533
617
|
for (const button of root.querySelectorAll('[data-step]')) button.setAttribute('aria-pressed', Number(button.dataset.step) === selected);
|
|
534
618
|
for (const button of detailList.querySelectorAll('[data-entry]')) button.setAttribute('aria-pressed', button.dataset.entry === selectedDetail);
|
|
535
619
|
for (const button of context.querySelectorAll('[data-criterion]')) button.setAttribute('aria-pressed', button.dataset.criterion === criterion);
|
|
620
|
+
if (!anatomy.hidden && anatomyFlow === flow) {
|
|
621
|
+
anatomySelect.value = selected;
|
|
622
|
+
for (const edge of anatomyStage.querySelectorAll('.ar-anatomy-edge')) edge.toggleAttribute('data-active', Number(edge.dataset.anatomyEdge) === selected);
|
|
623
|
+
for (const node of anatomyStage.querySelectorAll('[data-anatomy-indices]')) {
|
|
624
|
+
node.toggleAttribute('data-active', node.dataset.anatomyIndices.split(' ').includes(String(selected)));
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
async function showGraphMap() {
|
|
630
|
+
const request = ++anatomyRequest;
|
|
631
|
+
const view = layout;
|
|
632
|
+
const currentCamera = view === 'iso' ? camera : null;
|
|
633
|
+
graphCamera.closest('label').hidden = view !== 'iso';
|
|
634
|
+
if (anatomyFlow === flow && anatomyView === view && anatomyCamera === currentCamera) return;
|
|
635
|
+
const currentFlow = flow;
|
|
636
|
+
anatomyStage.parentElement.hidden = true;
|
|
637
|
+
anatomySelect.closest('label').hidden = true;
|
|
638
|
+
anatomyStatus.textContent = 'Dibujando las llamadas…';
|
|
639
|
+
try {
|
|
640
|
+
anatomyModule ??= await import('./anatomy.mjs');
|
|
641
|
+
if (request !== anatomyRequest || anatomy.hidden) return;
|
|
642
|
+
const edges = anatomyModule.renderGraphMap(anatomyStage, currentFlow, graphProject.selected, { view, camera: currentCamera });
|
|
643
|
+
cycleNote.hidden = !edges?.some(edge => edge.cycle);
|
|
644
|
+
anatomyStatus.textContent = edges ? '' : 'No hay conexiones disponibles para este punto de entrada.';
|
|
645
|
+
anatomyStage.parentElement.hidden = !edges;
|
|
646
|
+
anatomySelect.closest('label').hidden = !edges;
|
|
647
|
+
if (edges) {
|
|
648
|
+
anatomySelect.replaceChildren(...edges.map(({ index, cycle }) => new Option(`${currentFlow[index].symbol}${cycle ? ' · Ciclo' : ''}`, index)));
|
|
649
|
+
anatomyFlow = currentFlow;
|
|
650
|
+
anatomyView = view;
|
|
651
|
+
anatomyCamera = currentCamera;
|
|
652
|
+
renderEvidence();
|
|
653
|
+
}
|
|
654
|
+
} catch {
|
|
655
|
+
if (request !== anatomyRequest || anatomy.hidden) return;
|
|
656
|
+
anatomyStatus.textContent = 'No se pudo cargar el mapa. Puedes seguir explorando en Pasos.';
|
|
657
|
+
}
|
|
536
658
|
}
|
|
537
659
|
|
|
538
660
|
function renderLayout() {
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
661
|
+
const currentLayout = graphProject && mode !== 'learn' ? 'steps' : layout;
|
|
662
|
+
if (graphProject) root.querySelector('.ar-layout').hidden = mode !== 'learn';
|
|
663
|
+
map.hidden = !!graphProject || currentLayout !== 'iso';
|
|
664
|
+
steps.hidden = currentLayout !== 'steps';
|
|
665
|
+
anatomy.hidden = !graphProject || currentLayout === 'steps';
|
|
666
|
+
for (const button of root.querySelectorAll('[data-layout]')) button.setAttribute('aria-pressed', button.dataset.layout === currentLayout);
|
|
667
|
+
if (!map.hidden) renderScene();
|
|
668
|
+
if (!anatomy.hidden) showGraphMap();
|
|
543
669
|
renderEvidence();
|
|
544
670
|
}
|
|
545
671
|
|
|
@@ -632,7 +758,7 @@
|
|
|
632
758
|
function restore(saved) {
|
|
633
759
|
if (!saved || !['learn', 'diff', 'review'].includes(saved.mode)) return;
|
|
634
760
|
mode = saved.mode;
|
|
635
|
-
if (
|
|
761
|
+
if (['steps', 'iso'].includes(saved.layout) || (graphProject && saved.layout === 'anatomy')) layout = saved.layout;
|
|
636
762
|
if (Object.hasOwn(cameras, saved.camera ?? '')) camera = saved.camera;
|
|
637
763
|
if (saved.detail === 'module' || Object.hasOwn(details, saved.detail ?? '')) detail = saved.detail;
|
|
638
764
|
for (const layer of Object.keys(layers)) if (typeof saved.layers?.[layer] === 'boolean') layers[layer] = saved.layers[layer];
|
|
@@ -640,6 +766,7 @@
|
|
|
640
766
|
selectedDetail = catalogue.has(saved.selectedDetail) ? saved.selectedDetail : null;
|
|
641
767
|
if (mode === 'review' && review.criteria.some(entry => entry.id === saved.criterion)) criterion = saved.criterion;
|
|
642
768
|
map.querySelector('[data-camera]').value = camera;
|
|
769
|
+
graphCamera.value = camera;
|
|
643
770
|
map.querySelector('[data-detail]').value = detail;
|
|
644
771
|
for (const input of map.querySelectorAll('[data-layer]')) input.checked = layers[input.dataset.layer];
|
|
645
772
|
}
|
|
@@ -695,6 +822,20 @@
|
|
|
695
822
|
context.addEventListener('change', event => {
|
|
696
823
|
if (event.target.matches('[data-patch-menu]')) showPatch(event.target.value);
|
|
697
824
|
});
|
|
825
|
+
function selectAnatomyEdge(index) {
|
|
826
|
+
selected = Number(index);
|
|
827
|
+
renderEvidence();
|
|
828
|
+
save();
|
|
829
|
+
}
|
|
830
|
+
anatomySelect.addEventListener('change', () => selectAnatomyEdge(anatomySelect.value));
|
|
831
|
+
graphCamera.addEventListener('change', () => {
|
|
832
|
+
camera = graphCamera.value;
|
|
833
|
+
showGraphMap();
|
|
834
|
+
save();
|
|
835
|
+
});
|
|
836
|
+
anatomyStage.addEventListener('click', event => {
|
|
837
|
+
if (event.target.matches('.ar-anatomy-hit')) selectAnatomyEdge(event.target.dataset.anatomyEdge);
|
|
838
|
+
});
|
|
698
839
|
entrySelect.addEventListener('change', async () => {
|
|
699
840
|
const oldValue = graphProject.selected;
|
|
700
841
|
entryStatus.textContent = 'Cargando llamadas…';
|