Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 810x 810x 810x 1620x 1620x 1620x 1620x 1620x 1620x 1620x 1620x 1620x 1620x 1620x 1620x 2835x 2835x 2835x 2835x 2835x 2835x 2835x 2835x 2835x 2970x 2970x 2970x 2970x 2970x 2970x 2835x 2835x 2835x 2835x 2835x 2835x | import {pipe, Function, Record, String, flow} from '#util'
import {
elbowSet,
lineSet,
type ElbowSetName,
type LineSetName,
teeSet,
type TeeSetName,
} from '../../glyph.js'
/**
* A role for a glyph in a glyph role map.
* @category drawing
*/
export type GlyphRole = (typeof glyphRoles)[number]
/**
* Maps roles to glyphs.
* @category drawing
*/
export type GlyphSet = Record<GlyphRole, string>
/**
* A named {@link GlyphSet}.
* @category drawing
*/
export type GlyphSetName = (typeof glyphSetNames)[number]
/**
* Bullet role names.
* @category drawing
*/
export const bulletRoles = ['rootBullet', 'branchBullet', 'leafBullet'] as const
/**
* Glyph role names.
* @category drawing
*/
export const glyphRoles = [
'elbow',
'hLine',
'indent',
'rightTee',
'space',
'tee',
'vLine',
...bulletRoles,
] as const
/**
* Glyph set names.
* @category drawing
*/
export const glyphSetNames = [
'ascii',
'bullets',
'dashed',
'dashedWide',
'dotted',
'double',
'hDouble',
'hThick',
'round',
'space',
'thick',
'thickDashed',
'thickDashedWide',
'thickDotted',
'hThickDashed',
'hThickDashedWide',
'hThickDotted',
'thin',
'unix',
'unixRound',
'vDouble',
'vThick',
'vThickDashed',
'vThickDashedWide',
'vThickDotted',
] as const
const noBullets = Record.monoRecord('')(...bulletRoles)
const defaultSet: GlyphSet = {
...Record.monoRecord('')(...glyphRoles),
...getLines('space'),
...noBullets,
tee: teeSet('space').bottom,
rightTee: teeSet('space').right,
elbow: elbowSet('space').bottomLeft,
space: ' ',
indent: ' ',
}
const unix: GlyphSet = {
...defaultSet,
hLine: lineSet('thin').top,
vLine: ' ' + lineSet('thin').left,
elbow: ' ' + elbowSet('thin').bottomLeft,
tee: lineSet('thin').bottom,
rightTee: ' ' + teeSet('thin').right,
indent: String.repeat(2)(lineSet('thin').top),
space: ' ',
}
const glyphSets: Record<GlyphSetName, GlyphSet> = {
ascii: {...defaultSet, ...fromSet('ascii'), indent: lineSet('ascii').top},
bullets: {
...defaultSet,
rootBullet: '►',
branchBullet: '∘',
leafBullet: '∙',
},
dashed: pipe('thin', fromSet, withLines('dashed')),
dashedWide: pipe('thin', fromSet, withLines('dashedWide')),
dotted: pipe('thin', fromSet, withLines('dotted')),
double: fromSet('double'),
hDouble: fromSet('hDouble'),
hThick: fromSet('hThick'),
hThickDashed: pipe(
'hThick',
fromSet,
withHLine('thickDashed'),
withVLine('dashed'),
),
hThickDashedWide: pipe(
'hThick',
fromSet,
withHLine('thickDashedWide'),
withVLine('dashedWide'),
),
hThickDotted: pipe(
'hThick',
fromSet,
withHLine('thickDotted'),
withVLine('dotted'),
),
round: {...fromSet('thin'), elbow: elbowSet('round').bottomLeft},
space: defaultSet,
thick: fromSet('thick'),
thickDashed: pipe('thick', fromSet, withLines('thickDashed')),
thickDashedWide: pipe('thick', fromSet, withLines('thickDashedWide')),
thickDotted: pipe('thick', fromSet, withLines('thickDotted')),
thin: fromSet('thin'),
unix,
unixRound: {...unix, elbow: ' ' + elbowSet('round').bottomLeft},
vThick: fromSet('vThick'),
vThickDashed: pipe(
'vThick',
fromSet,
withHLine('dashed'),
withVLine('thickDashed'),
),
vThickDashedWide: pipe(
'vThick',
fromSet,
withHLine('dashedWide'),
withVLine('thickDashedWide'),
),
vThickDotted: pipe(
'vThick',
fromSet,
withHLine('dotted'),
withVLine('thickDotted'),
),
vDouble: fromSet('vDouble'),
}
/**
* Get a glyph set by name.
* @example
* import {Draw} from 'effect-tree'
*
* const glyph = Draw.glyphSet('thick').elbow
*
* expect(glyph).toBe('┗')
* @param name Name of glyph set to get.
* @returns Requested glyph set.
* @category drawing
* @function
*/
export const glyphSet = (name: GlyphSetName): GlyphSet => glyphSets[name]
function withLines(lines: LineSetName): Function.EndoOf<GlyphSet> {
return flow(withHLine(lines), withVLine(lines))
}
function withVLine(lines: LineSetName): Function.EndoOf<GlyphSet> {
return glyphSet => ({
...glyphSet,
vLine: lineSet(lines).left,
})
}
function withHLine(lines: LineSetName): Function.EndoOf<GlyphSet> {
return glyphSet => ({
...glyphSet,
hLine: lineSet(lines).top,
})
}
function fromSet(set: LineSetName & TeeSetName & ElbowSetName): GlyphSet {
return {
...defaultSet,
...getLines(set),
...getTees(set),
elbow: elbowSet(set).bottomLeft,
indent: lineSet(set).top,
}
}
function getLines(set: LineSetName) {
return {
hLine: lineSet(set).top,
vLine: lineSet(set).left,
}
}
function getTees(set: TeeSetName) {
return {
tee: teeSet(set).bottom,
rightTee: teeSet(set).right,
}
}
|