textmode.figlet.js 1.0.1 → 1.0.3-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +73 -134
- package/dist/textmode.figlet.esm.js +1 -1
- package/dist/textmode.figlet.umd.js +1 -1
- package/dist/types/augmentations/index.d.ts +0 -1
- package/dist/types/augmentations/textmode.d.ts +28 -1
- package/dist/types/error/FigletError.d.ts +0 -1
- package/dist/types/extensions/index.d.ts +0 -1
- package/dist/types/extensions/textmodifier.d.ts +0 -1
- package/dist/types/figfont/FigFontParser.d.ts +0 -1
- package/dist/types/figfont/FigLayoutEngine.d.ts +0 -1
- package/dist/types/figfont/FigSmushRules.d.ts +0 -1
- package/dist/types/figfont/TextmodeFigFont.d.ts +30 -1
- package/dist/types/figfont/index.d.ts +0 -1
- package/dist/types/figfont/types.d.ts +193 -30
- package/dist/types/index.d.ts +40 -2
- package/dist/types/plugin/FigletPlugin.d.ts +4 -1
- package/dist/types/plugin/index.d.ts +0 -1
- package/dist/types/state/figletState.d.ts +0 -1
- package/dist/types/utils/Disposable.d.ts +0 -1
- package/package.json +84 -47
- package/dist/types/augmentations/index.d.ts.map +0 -1
- package/dist/types/augmentations/textmode.d.ts.map +0 -1
- package/dist/types/error/FigletError.d.ts.map +0 -1
- package/dist/types/extensions/index.d.ts.map +0 -1
- package/dist/types/extensions/textmodifier.d.ts.map +0 -1
- package/dist/types/figfont/FigFontParser.d.ts.map +0 -1
- package/dist/types/figfont/FigLayoutEngine.d.ts.map +0 -1
- package/dist/types/figfont/FigSmushRules.d.ts.map +0 -1
- package/dist/types/figfont/TextmodeFigFont.d.ts.map +0 -1
- package/dist/types/figfont/index.d.ts.map +0 -1
- package/dist/types/figfont/types.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/plugin/FigletPlugin.d.ts.map +0 -1
- package/dist/types/plugin/index.d.ts.map +0 -1
- package/dist/types/state/figletState.d.ts.map +0 -1
- package/dist/types/utils/Disposable.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -1,166 +1,105 @@
|
|
|
1
|
-
# textmode.figlet.js
|
|
1
|
+
# textmode.figlet.js
|
|
2
2
|
|
|
3
3
|
<div align="center">
|
|
4
4
|
|
|
5
|
-
<
|
|
6
|
-
<tr>
|
|
7
|
-
<td align="center">
|
|
8
|
-
<a href="https://www.typescriptlang.org/"><img alt="TypeScript badge" src="https://img.shields.io/badge/TypeScript-3178C6?logo=typescript&logoColor=white" /></a> <a href="https://vitejs.dev/"><img alt="Vite badge" src="https://img.shields.io/badge/Vite-646CFF?logo=vite&logoColor=white" /></a> <a href="http://www.figlet.org/"><img alt="FIGlet badge" src="https://img.shields.io/badge/FIGlet-111111" /></a>
|
|
9
|
-
</td>
|
|
10
|
-
<td align="center">
|
|
11
|
-
<a href="https://code.textmode.art/"><img alt="docs badge" src="https://img.shields.io/badge/docs-vitepress-646cff?logo=vitepress&logoColor=white" /></a> <a href="https://discord.gg/sjrw8QXNks"><img alt="Discord badge" src="https://img.shields.io/discord/1357070706181017691?color=5865F2&label=Discord&logo=discord&logoColor=white" /></a>
|
|
12
|
-
</td>
|
|
13
|
-
<td align="center">
|
|
14
|
-
<a href="https://ko-fi.com/V7V8JG2FY"><img alt="Ko-fi badge" src="https://shields.io/badge/ko--fi-donate-ff5f5f?logo=ko-fi" /></a> <a href="https://github.com/sponsors/humanbydefinition"><img alt="GitHub Sponsors badge" src="https://img.shields.io/badge/sponsor-30363D?logo=GitHub-Sponsors&logoColor=%23EA4AAA" /></a>
|
|
15
|
-
</td>
|
|
16
|
-
</tr>
|
|
17
|
-
</table>
|
|
18
|
-
|
|
19
|
-
</div>
|
|
20
|
-
|
|
21
|
-
`textmode.figlet.js` is an add-on library for `textmode.js` that provides FIGlet / FIGfont support. It includes a FIGfont parser, layout engine, and rendering API that integrates with the `Textmodifier` system in `textmode.js`, allowing you to draw FIGlet text with configurable layout behavior and measurement helpers.
|
|
22
|
-
|
|
23
|
-
## Features
|
|
24
|
-
|
|
25
|
-
- Parse raw `.flf` sources into reusable `TextmodeFigFont` instances
|
|
26
|
-
- Load FIGfonts at runtime with `loadFigFont()`
|
|
27
|
-
- Draw FIGlet text with configurable horizontal and vertical layout behavior
|
|
28
|
-
- Measure rendered output with width, height, and bounds helpers before drawing
|
|
29
|
-
- Store alignment and baseline preferences per `Textmodifier` instance
|
|
30
|
-
|
|
31
|
-
## Installation
|
|
32
|
-
|
|
33
|
-
### Prerequisites
|
|
34
|
-
|
|
35
|
-
To get started with `textmode.figlet.js`, you'll need:
|
|
36
|
-
|
|
37
|
-
- `textmode.js` `0.11.0` or newer
|
|
38
|
-
- A modern browser with the same runtime requirements as `textmode.js`
|
|
39
|
-
- Node.js `20.8.1+` and `npm` (optional, for ESM installation)
|
|
40
|
-
|
|
41
|
-
### UMD
|
|
42
|
-
|
|
43
|
-
To use `textmode.figlet.js` in a browser without a bundler, load the UMD builds for both `textmode.js` and this add-on. `textmode.js` must be loaded first so the FIGlet add-on can attach to the expected global runtime.
|
|
44
|
-
|
|
45
|
-
```html
|
|
46
|
-
<!doctype html>
|
|
47
|
-
<html lang="en">
|
|
48
|
-
<head>
|
|
49
|
-
<meta charset="utf-8" />
|
|
50
|
-
<title>textmode.figlet.js sketch</title>
|
|
5
|
+
<img alt="textmode.figlet.js — draw FIGlet in textmode" src=".github/assets/readme-og.png" />
|
|
51
6
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
</head>
|
|
55
|
-
<body>
|
|
56
|
-
<script src="./sketch.js"></script>
|
|
57
|
-
</body>
|
|
58
|
-
</html>
|
|
59
|
-
```
|
|
7
|
+
| [](https://www.typescriptlang.org/) [](https://vitejs.dev/) | [](https://code.textmode.art/api/textmode.figlet.js/) [](https://code.textmode.art/) [](https://discord.gg/sjrw8QXNks) | [](https://ko-fi.com/V7V8JG2FY) [](https://github.com/sponsors/humanbydefinition) |
|
|
8
|
+
|:---|:---|:---|
|
|
60
9
|
|
|
61
|
-
|
|
62
|
-
const t = textmode.create({
|
|
63
|
-
width: window.innerWidth,
|
|
64
|
-
height: window.innerHeight,
|
|
65
|
-
fontSize: 16,
|
|
66
|
-
plugins: [FigletPlugin],
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
t.setup(async () => {
|
|
70
|
-
const bulbhead = await t.loadFigFont('https://cdn.jsdelivr.net/gh/xero/figlet-fonts@master/Bulbhead.flf');
|
|
71
|
-
|
|
72
|
-
t.figFont(bulbhead);
|
|
73
|
-
t.figTextAlign('center');
|
|
74
|
-
t.figTextBaseline('center');
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
t.draw(() => {
|
|
78
|
-
t.background(8, 12, 24);
|
|
79
|
-
t.charColor(255, 220, 120);
|
|
80
|
-
t.figText('FIGLET', 0, 0, {
|
|
81
|
-
horizontalLayout: 'fitted',
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
t.windowResized(() => {
|
|
86
|
-
t.resizeCanvas(window.innerWidth, window.innerHeight);
|
|
87
|
-
});
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
The UMD bundle exposes `FigletPlugin` globally, along with the other runtime exports such as `TextmodeFigFont` and `FigFontParser`.
|
|
10
|
+
</div>
|
|
91
11
|
|
|
92
|
-
|
|
12
|
+
`textmode.figlet.js` is a FIGlet and FIGfont add-on for [`textmode.js`](https://github.com/humanbydefinition/textmode.js) for giving a sketch bold display typography. Its FIGfont parser, layout engine, and rendering API work with the core `Textmodifier` system to load, measure, and draw large text with configurable horizontal and vertical layout behavior.
|
|
93
13
|
|
|
94
|
-
|
|
14
|
+
FIGlet text needs more than a font file: fitting, smushing, direction, and placement all shape the final composition. Whether you are setting those rules or positioning a title precisely within a scene, `textmode.figlet.js` provides clear helpers for rendering, alignment, baselines, and bounds.
|
|
95
15
|
|
|
96
|
-
|
|
97
|
-
npm install textmode.js textmode.figlet.js
|
|
98
|
-
```
|
|
16
|
+
## Features
|
|
99
17
|
|
|
100
|
-
|
|
18
|
+
- **FIGfont loading and parsing** - Load `.flf` files from URLs or parse raw data with metadata and Unicode character access
|
|
19
|
+
- **Standards-aware layout** - Full-width, fitted, and smushed horizontal and vertical layouts with FIGlet smushing rules
|
|
20
|
+
- **Multiline wrapping** - Explicit line breaks plus word and character wrapping within configurable column limits
|
|
21
|
+
- **Bidirectional rendering** - Respect font-defined direction or explicitly render left-to-right and right-to-left text
|
|
22
|
+
- **textmode-native drawing** - Draw through `Textmodifier` with alignment, baseline, and per-cell foreground/background styling
|
|
23
|
+
- **Planning and measurement** - Generate render plans or grids and calculate width, height, and bounds without drawing
|
|
101
24
|
|
|
102
|
-
|
|
103
|
-
import { textmode } from 'textmode.js';
|
|
104
|
-
import { FigletPlugin } from 'textmode.figlet.js';
|
|
105
|
-
```
|
|
25
|
+
## Try it online first
|
|
106
26
|
|
|
107
|
-
|
|
27
|
+
Open [editor.textmode.art](https://editor.textmode.art/), a browser-based live-coding environment for the
|
|
28
|
+
complete official `textmode.js` ecosystem. Sketches run as you edit, with no local toolchain required.
|
|
108
29
|
|
|
109
|
-
|
|
30
|
+
The editor includes `textmode.js` and all four official add-ons: `textmode.export.js`, `textmode.filters.js`,
|
|
31
|
+
`textmode.figlet.js`, and `textmode.synth.js`.
|
|
110
32
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
33
|
+
- Write with Monaco-powered completions, hover documentation, and diagnostics.
|
|
34
|
+
- Start with a blank sketch, an included example, or a community gallery sketch.
|
|
35
|
+
- Keep code and preferences saved in the browser, then share sketches through URL-based links.
|
|
36
|
+
- Use microphone or line-input analysis for audio-reactive work, and create on desktop or mobile.
|
|
114
37
|
|
|
115
|
-
|
|
116
|
-
width: 800,
|
|
117
|
-
height: 600,
|
|
118
|
-
plugins: [FigletPlugin],
|
|
119
|
-
});
|
|
120
|
-
```
|
|
38
|
+
Use it to load and render FIGlet fonts while you iterate on a sketch.
|
|
121
39
|
|
|
122
|
-
|
|
40
|
+
## Installation
|
|
123
41
|
|
|
124
|
-
|
|
42
|
+
Follow the [official installation guide](https://code.textmode.art/docs/installation) to install
|
|
43
|
+
`textmode.figlet.js` alongside `textmode.js` with npm or browser-ready UMD bundles.
|
|
125
44
|
|
|
126
|
-
|
|
127
|
-
const bulbhead = await t.loadFigFont('https://cdn.jsdelivr.net/gh/xero/figlet-fonts@master/Bulbhead.flf');
|
|
45
|
+
## Next steps
|
|
128
46
|
|
|
129
|
-
|
|
47
|
+
- **[Read the documentation](https://code.textmode.art/)** for core concepts and plugin workflows.
|
|
48
|
+
- **[Browse the API reference](https://code.textmode.art/api/textmode.figlet.js/)** for the complete FIGfont and rendering API.
|
|
49
|
+
- **[Explore the examples](./examples/)** to see font loading, layout, and rendering patterns in action.
|
|
50
|
+
- **[Try the live editor](https://editor.textmode.art/)** to experiment with FIGlet text in the browser.
|
|
130
51
|
|
|
131
|
-
|
|
132
|
-
```
|
|
52
|
+
## Contributing
|
|
133
53
|
|
|
134
|
-
|
|
54
|
+
Thank you for considering contributing to this project! (✿◠‿◠)
|
|
135
55
|
|
|
136
|
-
|
|
56
|
+
Please read the [Contributing Guide](./CONTRIBUTING.md) to get started.
|
|
137
57
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
58
|
+
<!-- TEXTMODE-CONTRIBUTORS:START -->
|
|
59
|
+
<!-- prettier-ignore-start -->
|
|
60
|
+
<!-- Generated from https://github.com/humanbydefinition/code.textmode.art/blob/main/.vitepress/data/contributors.json and https://github.com/humanbydefinition/code.textmode.art/blob/main/.vitepress/data/contribution-types.json. Do not edit this section directly. -->
|
|
61
|
+
## Contributors
|
|
141
62
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
});
|
|
63
|
+
Thanks to the people who contribute code, documentation, design, examples, ideas, infrastructure, and care
|
|
64
|
+
across the textmode.js ecosystem.
|
|
145
65
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
66
|
+
<!-- markdownlint-disable MD033 -->
|
|
67
|
+
<table>
|
|
68
|
+
<tbody>
|
|
69
|
+
<tr>
|
|
70
|
+
<td align="center" valign="top" width="14.28%">
|
|
71
|
+
<a href="https://github.com/humanbydefinition">
|
|
72
|
+
<img src="https://github.com/humanbydefinition.png?s=100" width="100px" alt="humanbydefinition avatar" />
|
|
73
|
+
<br /><sub><b>humanbydefinition</b></sub>
|
|
74
|
+
</a>
|
|
75
|
+
<br /><span title="Code: Commits and pull requests" aria-label="Code: Commits and pull requests">💻</span> <span title="Documentation: README, guides, and API documentation" aria-label="Documentation: README, guides, and API documentation">📖</span> <span title="Design: User experience, branding, and visual design" aria-label="Design: User experience, branding, and visual design">🎨</span> <span title="Examples: Usage examples and creative sketches" aria-label="Examples: Usage examples and creative sketches">💡</span> <span title="Ideas and planning: Feature proposals, planning, and feedback" aria-label="Ideas and planning: Feature proposals, planning, and feedback">🤔</span> <span title="Maintenance: Refactoring and project upkeep" aria-label="Maintenance: Refactoring and project upkeep">🚧</span> <span title="Infrastructure: Continuous integration, hosting, and build systems" aria-label="Infrastructure: Continuous integration, hosting, and build systems">🚇</span> <span title="Tools: Developer and community tooling" aria-label="Tools: Developer and community tooling">🔧</span> <span title="Plugins and libraries: Plugin and utility library development" aria-label="Plugins and libraries: Plugin and utility library development">🔌</span> <span title="Code review: Reviewing pull requests" aria-label="Code review: Reviewing pull requests">👀</span>
|
|
76
|
+
</td>
|
|
77
|
+
<td align="center" valign="top" width="14.28%">
|
|
78
|
+
<a href="https://github.com/trintlermint">
|
|
79
|
+
<img src="https://github.com/trintlermint.png?s=100" width="100px" alt="trintlermint avatar" />
|
|
80
|
+
<br /><sub><b>trintlermint</b></sub>
|
|
81
|
+
</a>
|
|
82
|
+
<br /><span title="Design: User experience, branding, and visual design" aria-label="Design: User experience, branding, and visual design">🎨</span> <span title="Examples: Usage examples and creative sketches" aria-label="Examples: Usage examples and creative sketches">💡</span>
|
|
83
|
+
</td>
|
|
84
|
+
</tr>
|
|
85
|
+
</tbody>
|
|
86
|
+
</table>
|
|
87
|
+
<!-- markdownlint-enable MD033 -->
|
|
150
88
|
|
|
151
|
-
|
|
89
|
+
Contribution details and profile links are maintained on the [textmode.js contributors page](https://code.textmode.art/docs/contributors).
|
|
90
|
+
<!-- prettier-ignore-end -->
|
|
91
|
+
<!-- TEXTMODE-CONTRIBUTORS:END -->
|
|
152
92
|
|
|
153
|
-
##
|
|
93
|
+
## License
|
|
154
94
|
|
|
155
|
-
|
|
156
|
-
- `figTextBaseline('top' | 'center' | 'baseline' | 'bottom')`
|
|
95
|
+
`textmode.figlet.js` is licensed under the [MIT License](./LICENSE).
|
|
157
96
|
|
|
158
|
-
|
|
97
|
+
---
|
|
159
98
|
|
|
160
|
-
|
|
99
|
+
<div align="center">
|
|
161
100
|
|
|
162
|
-
|
|
101
|
+
<br />
|
|
163
102
|
|
|
164
|
-
|
|
103
|
+
**[↑ back to top](#textmodefigletjs)**
|
|
165
104
|
|
|
166
|
-
|
|
105
|
+
</div>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var t=Object.defineProperty,e=(e,n,r)=>((e,n,r)=>n in e?t(e,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[n]=r)(e,"symbol"!=typeof n?n+"":n,r);import{color as n}from"textmode.js";class r extends Error{constructor(t,e){super(r.formatMessage(t,e)),this.name="FigletError"}static formatMessage(t,e){if(!e||0===Object.keys(e).length)return t;return`${t}\n\nContext:${Object.entries(e).map(([t,e])=>`\n - ${t}: ${r.formatValue(e)}`).join("")}`}static formatValue(t){return null===t?"null":void 0===t?"undefined":"string"==typeof t?`"${t}"`:"number"==typeof t||"boolean"==typeof t?t+"":Array.isArray(t)?`[${t.map(t=>r.formatValue(t)).join(", ")}]`:"object"==typeof t?JSON.stringify(t):t+""}}const i=[...Array.from({length:95},(t,e)=>e+32),196,214,220,228,246,252,223];class s{static t(t){if(0===t.length)throw new r("Cannot parse an empty FIGfont file.");const e=t.replace(/\r\n?/g,"\n").split("\n"),n=e[0];if(!n)throw new r("Missing FIGfont header line.");const i=this.i(n);let s=1+i.commentLines;if(s>e.length)throw new r("FIGfont comment line count exceeds file length.",{commentLines:i.commentLines,totalLines:e.length});const o=new Map;return s=this.o(e,s,i,o),this.l(e,s,i,o),{header:i,characters:o}}static i(t){const e=t.trim().split(/\s+/),n=e[0]??"";if(n.length<6)throw new r("Invalid FIGfont header token.",{headerToken:n});const i=n.slice(0,5),s=n.slice(5);if("flf2a"!==i)throw new r("Unsupported FIGfont signature.",{signature:i});if(1!==s.length)throw new r("FIGfont hardblank must be a single character.",{hardblank:s});if(e.length<6)throw new r("Incomplete FIGfont header.",{headerLine:t});return{signature:i,hardblank:s,height:this.u(e[1],"height"),baseline:this.u(e[2],"baseline"),maxLength:this.u(e[3],"maxLength"),oldLayout:this.u(e[4],"oldLayout"),commentLines:this.u(e[5],"commentLines"),printDirection:this.u(e[6]??"0","printDirection"),fullLayout:this.u(e[7]??"0","fullLayout"),codetagCount:this.u(e[8]??"0","codetagCount")}}static o(t,e,n,r){let s=e;for(const e of i){const i=this.h(t,s,n.height,e);r.set(e,i),s+=n.height}return s}static l(t,e,n,r){var i;let s=e;for(;s<t.length;){const e=(null==(i=t[s])?void 0:i.trim())??"";if(0===e.length){s+=1;continue}const o=this._(e);s+=1;const a=this.h(t,s,n.height,o);r.set(o,a),s+=n.height}}static h(t,e,n,i){if(e+n>t.length)throw new r("Unexpected end of FIGfont character data.",{codePoint:i,startIndex:e,height:n,totalLines:t.length});const s=[];let o=0;for(let a=0;a<n;a+=1){const n=t[e+a]??"";if(0===n.length)throw new r("Encountered an empty FIGcharacter row.",{codePoint:i,row:a,startIndex:e});const l=n.at(-1);if(!l)throw new r("Failed to determine FIGcharacter endmark.",{codePoint:i,row:a});const c=n.replace(RegExp(this.escapeForRegExp(l)+"+$"),"");s.push(c),o=Math.max(o,c.length)}return{code:i,lines:s,width:o}}static _(t){const e=t.split(/\s+/,1)[0];if(/^[-+]?0x[0-9a-f]+$/i.test(e))return Number.parseInt(e,16);if(/^[-+]?0[0-7]+$/.test(e))return Number.parseInt(e,8);if(/^[-+]?\d+$/.test(e))return Number.parseInt(e,10);throw new r("Invalid FIGfont code tag.",{codetagLine:t})}static u(t,e){if(!/^-?\d+$/.test(t))throw new r("Invalid FIGfont header value.",{field:e,token:t});return Number.parseInt(t,10)}static escapeForRegExp(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}}class o{static p(t){return 0!==t.fullLayout?63&t.fullLayout:t.oldLayout>0?63&t.oldLayout:0}static m(t){return 7936&t.fullLayout}static I(t,e,n,r){return" "===t?e:" "===e?t:0===r?this.v(t,e,n):(0!==(r&this.RULE_EQUAL_CHARACTER)?this.L(t,e,n):null)??(0!==(r&this.RULE_UNDERSCORE)?this.C(t,e):null)??(0!==(r&this.RULE_HIERARCHY)?this.R(t,e):null)??(0!==(r&this.RULE_OPPOSITE_PAIR)?this.F(t,e):null)??(0!==(r&this.RULE_BIG_X)?this.A(t,e):null)??(0!==(r&this.RULE_HARDBLANK)?this.T(t,e,n):null)}static v(t,e,n){return" "===t?e:" "===e?t:e}static U(t,e,n){return" "===t?e:" "===e?t:0===n?this.v(t,e," "):(0!==(n&this.VERTICAL_RULE_EQUAL_CHARACTER)?this.L(t,e," "):null)??(0!==(n&this.VERTICAL_RULE_UNDERSCORE)?this.C(t,e):null)??(0!==(n&this.VERTICAL_RULE_HIERARCHY)?this.R(t,e):null)??(0!==(n&this.VERTICAL_RULE_HORIZONTAL_LINE)?this.H(t,e):null)??(0!==(n&this.VERTICAL_RULE_VERTICAL_LINE_SUPERSMUSH)?this.S(t,e):null)}static L(t,e,n){return t===e&&t!==n?t:null}static C(t,e){const n="|/\\[]{}()<>";return"_"===t&&n.includes(e)?e:"_"===e&&n.includes(t)?t:null}static R(t,e){const n=["|","/\\","[]","{}","()","<>"],r=n.findIndex(e=>e.includes(t)),i=n.findIndex(t=>t.includes(e));return-1===r||-1===i||r===i?null:r>i?t:e}static F(t,e){return["[]","][","{}","}{","()",")("].includes(`${t}${e}`)?"|":null}static A(t,e){const n=`${t}${e}`;return"/\\"===n?"|":"\\/"===n?"Y":"><"===n?"X":null}static T(t,e,n){return t===n&&e===n?n:null}static H(t,e){const n=`${t}${e}`;return"-_"===n||"_-"===n?"=":null}static S(t,e){return"|"===t&&"|"===e?"|":null}}e(o,"RULE_EQUAL_CHARACTER",1),e(o,"RULE_UNDERSCORE",2),e(o,"RULE_HIERARCHY",4),e(o,"RULE_OPPOSITE_PAIR",8),e(o,"RULE_BIG_X",16),e(o,"RULE_HARDBLANK",32),e(o,"VERTICAL_RULE_EQUAL_CHARACTER",256),e(o,"VERTICAL_RULE_UNDERSCORE",512),e(o,"VERTICAL_RULE_HIERARCHY",1024),e(o,"VERTICAL_RULE_HORIZONTAL_LINE",2048),e(o,"VERTICAL_RULE_VERTICAL_LINE_SUPERSMUSH",4096);class a{constructor(t){e(this,"_header"),e(this,"_horizontalRuleMask"),e(this,"_verticalRuleMask"),this.$=t,this.k=o.p(t),this.M=o.m(t)}O(t,e){const n=t.map((t,e)=>({inputIndex:e,inputChar:String.fromCodePoint(t.code)})),r=this.G(t,n,e,0),i=Array.from({length:r.rows},()=>Array.from({length:r.cols},()=>" "));for(const t of r.cells)i[t.row][t.col]=t.char;return i}G(t,e,n,r){if(0===t.length)return{lineIndex:r,cells:[],cols:0,rows:this.$.height};let i=this.N(t[0],e[0],r),s=t[0].width;for(let a=1;a<t.length;a+=1){const l=t[a],c=e[a]??{inputIndex:a,inputChar:String.fromCodePoint(l.code)},u=s-this.P(i,s,l,n),h=Math.max(s,u+l.width),f=i.map(t=>Array.from({length:h},(e,n)=>t[n]));for(let t=0;t<this.$.height;t+=1){const e=l.lines[t]??"",n=f[t];for(let i=0;i<l.width;i+=1){const s=e[i]??" ";if(" "===s)continue;const a=u+i,h=n[a],f=this.V(a,t,i,r,l,c,s);if(!h){n[a]=f;continue}const d=o.I(h.char,s,this.$.hardblank,this.k);n[a]=this.D(h,f,d??s)}}i=f,s=h}return this.B(i,s,r)}j(t,e){var n;if(0===t.length)return{cells:[],lines:[],cols:0,rows:0};let r=this.W(t[0]),i=t[0].cols,s=t[0].rows;const a=[this.q(t[0],0)];for(let l=1;l<t.length;l+=1){const c=t[l],u=s-this.X(r,s,i,c,e),h=Math.max(i,c.cols),f=Math.max(s,u+c.rows),d=Array.from({length:f},(t,e)=>Array.from({length:h},(t,n)=>{var i;return null==(i=r[e])?void 0:i[n]}));for(const t of c.cells){const e=u+t.row,r=t.col,i=null==(n=d[e])?void 0:n[r];if(!i){d[e][r]={...t,row:e};continue}const s=o.U(i.char,t.char,this.M);d[e][r]=this.D(i,{...t,row:e},s??t.char)}r=d,i=h,s=f,a.push(this.q(c,u))}return this.Y(r,i,s,a)}P(t,e,n,r){var i;if("full"===r)return 0;for(let s=e;s>=0;s-=1){let o=!0;for(let a=0;a<this.$.height&&o;a+=1){const l=t[a]??[],c=n.lines[a]??"";for(let t=0;t<s;t+=1){const n=(null==(i=l[e-s+t])?void 0:i.char)??" ",a=c[t]??" ";if(!this.J(n,a,r)){o=!1;break}}}if(o)return s}return 0}J(t,e,n){return" "===t||" "===e||"fitted"!==n&&null!==o.I(t,e,this.$.hardblank,this.k)}N(t,e={inputIndex:0,inputChar:String.fromCodePoint(t.code)},n=0){return Array.from({length:this.$.height},(r,i)=>{const s=t.lines[i]??"";return Array.from({length:t.width},(r,o)=>{const a=s[o]??" ";return" "===a?void 0:this.V(o,i,o,n,t,e,a)})})}V(t,e,n,r,i,s,o){return{char:o,col:t,row:e,inputIndex:s.inputIndex,inputChar:s.inputChar,figCharCode:i.code,subRow:e,subCol:n,lineIndex:r}}D(t,e,n){return n===t.char?t:{...e,char:n}}B(t,e,n){const r=[];for(let i=0;i<this.$.height;i+=1){const s=t[i]??[];for(let t=0;t<e;t+=1){const e=s[t];!e||e.char===this.$.hardblank||r.push({...e,col:t,row:i,lineIndex:n})}}return{lineIndex:n,cells:r,cols:e,rows:this.$.height}}X(t,e,n,r,i){var s,o;if("full"===i)return 0;const a=this.W(r),l=Math.min(e,r.rows),c=Math.max(n,r.cols);for(let n=l;n>=0;n-=1){let r=!0;for(let l=0;l<n&&r;l+=1){const u=t[e-n+l]??[],h=a[l]??[];for(let t=0;t<c;t+=1){const e=(null==(s=u[t])?void 0:s.char)??" ",n=(null==(o=h[t])?void 0:o.char)??" ";if(!this.K(e,n,i)){r=!1;break}}}if(r)return n}return 0}K(t,e,n){return" "===t||" "===e||"fitted"!==n&&null!==o.U(t,e,this.M)}W(t){const e=Array.from({length:t.rows},()=>Array.from({length:t.cols},()=>{}));for(const n of t.cells)e[n.row][n.col]=n;return e}q(t,e){return{...t,cells:t.cells.map(t=>({...t,row:t.row+e}))}}Y(t,e,n,r){var i;const s=[];for(let r=0;r<n;r+=1)for(let n=0;n<e;n+=1){const e=null==(i=t[r])?void 0:i[n];e&&s.push({...e,row:r,col:n})}return{cells:s,lines:r,cols:e,rows:n}}}class l{constructor(){e(this,"_onDisposeCallbacks",new Set)}Z(t){this.tt.add(t)}dispose(){for(const t of this.tt)t();this.tt.clear()}}class c extends l{constructor(t,n,r){super(),e(this,"_name"),e(this,"_header"),e(this,"_characters"),e(this,"_layoutEngine"),this.et=t,this.$=n,this.nt=r,this.rt=new a(n)}static async it(t){const e=await fetch(t);if(!e.ok)throw new r("Failed to load FIGfont file.",{source:t+"",status:e.status,statusText:e.statusText});const n=await e.text();return this.st(this.ot(t),n)}static st(t,e){const n=s.t(e);return new c(t,n.header,n.characters)}getCharacter(t){var e;const n="number"==typeof t?t:null==(e=Array.from(t)[0])?void 0:e.codePointAt(0);if(void 0!==n)return u(this.nt.get(n))}planText(t,e={}){const n=e.horizontalLayout??this.defaultLayout,r=e.verticalLayout??this.defaultVerticalLayout,i=this.lt(e.direction),s=this.ct(t).map(t=>this.ut(t,i)).flatMap(t=>this.ht(t,n,e)).map((t,e)=>{const r=this.ft(t);return this.rt.G(r.map(t=>t.figChar),r.map(({inputChar:t,inputIndex:e})=>({inputChar:t,inputIndex:e})),n,e)}),o=this.rt.j(s,r);return{cells:o.cells,lines:o.lines,cols:o.cols,rows:o.rows,direction:i}}renderText(t,e={}){const n=this.planText(t,e),r=Array.from({length:n.rows},()=>Array.from({length:n.cols},()=>" "));for(const t of n.cells)r[t.row][t.col]=t.char;return{grid:r,cols:n.cols,rows:n.rows}}measureText(t,e={}){const n=this.planText(t,e);return{cols:n.cols,rows:n.rows}}get name(){return this.et}get header(){return{...this.$}}get characters(){return new Map(Array.from(this.nt,([t,e])=>[t,u(e)]))}get hardblank(){return this.$.hardblank}get height(){return this.$.height}get baseline(){return this.$.baseline}get defaultLayout(){return 128&this.$.fullLayout?"smushed":64&this.$.fullLayout?"fitted":-1===this.$.oldLayout?"full":0===this.$.oldLayout?"fitted":this.$.oldLayout>0?"smushed":"full"}get defaultPrintDirection(){return 1===this.$.printDirection?"rtl":"ltr"}get defaultVerticalLayout(){return 16384&this.$.fullLayout?"smushed":8192&this.$.fullLayout?"fitted":"full"}static ot(t){const e=t instanceof URL?t.pathname:t,n=(e.split(/[?#]/,1)[0]??e).split("/").filter(Boolean).pop()??"figfont";return n.toLowerCase().endsWith(".flf")?n.slice(0,-4)||"figfont":n}ct(t){const e=[[]];for(const[n,r]of Array.from(t).entries())"\n"!==r?e[e.length-1].push({character:r,inputIndex:n}):e.push([]);return e}ut(t,e){return"rtl"===e?[...t].reverse():t}ft(t){const e=t.map(({character:t,inputIndex:e})=>({figChar:this.getCharacter(t)??this.getCharacter(32),inputChar:t,inputIndex:e})),n=e.find(t=>void 0===t.figChar);if(n)throw new r("FIGfont is missing a required character for layout.",{character:n.inputChar,index:n.inputIndex});return e}ht(t,e,n){const r="number"==typeof n.maxCols&&Number.isFinite(n.maxCols)?Math.floor(n.maxCols):void 0,i=n.wrap??"none";return 0===t.length||!r||r<1||"none"===i?[t]:"char"===i?this.dt(t,e,r):this.gt(t,e,r)}gt(t,e,n){const r=this._t(t);if(!r.some(t=>!t.isWhitespace))return[t];const i=[];let s=[],o=[];for(const t of r){if(t.isWhitespace){s.length>0&&(o=t.characters);continue}const r=0===s.length?t.characters:s.concat(o,t.characters);s.length>0&&this.wt(r,e)>n?(i.push(s),s=t.characters.slice()):s=r,o=[]}return 0===s.length?[[]]:(i.push(s),i)}dt(t,e,n){const r=[];let i=[];for(const s of t){const t=i.concat(s);i.length>0&&this.wt(t,e)>n?(r.push(i),i=[s]):i=t}return 0===i.length?[[]]:(r.push(i),r)}wt(t,e){const n=this.ft(t);return this.rt.G(n.map(t=>t.figChar),n.map(({inputChar:t,inputIndex:e})=>({inputChar:t,inputIndex:e})),e,0).cols}_t(t){const e=[];for(const n of t){const t=/\s/u.test(n.character),r=e[e.length-1];r&&r.isWhitespace===t?r.characters.push(n):e.push({isWhitespace:t,characters:[n]})}return e}lt(t){return"ltr"===t||"rtl"===t?t:this.defaultPrintDirection}}function u(t){if(t)return{...t,lines:[...t.lines]}}const h="textmode.figlet.js",f="1.0.1",d=Symbol.for("textmode.figlet.state");function g(t){const e=t;return e[d]||(e[d]={activeFont:void 0,align:"left",baseline:"baseline"}),e[d]}const _=["loadFigFont","parseFigFont","figFont","figText","figTextWidth","figTextHeight","figTextBounds","figTextAlign","figTextBaseline"];function p(t,e){if(void 0!==t)return"function"==typeof t?t(e):t}function w(t,e,r){return r instanceof n.TextmodeColor||"string"==typeof r||"number"==typeof r?"charColor"===e?void t.charColor(r):void t.cellColor(r):4===r.length?"charColor"===e?void t.charColor(r[0],r[1],r[2],r[3]):void t.cellColor(r[0],r[1],r[2],r[3]):void("charColor"!==e?t.cellColor(r[0],r[1],r[2]):t.charColor(r[0],r[1],r[2]))}function m(t){const e=g(t).activeFont;if(!e)throw new r("No FIGlet font is active. Call figFont() first.");return e}function I(t,e){var n;null==(n=t.It)||n.call(t,e)}function v(t,e,n){Object.defineProperty(t,e,{value:n,writable:!0,configurable:!0,enumerable:!1})}function L(t){v(t,"loadFigFont",async function(t){const e=await c.it(t);return I(this,e),e}),v(t,"parseFigFont",function(t,e){const n=c.st(t,e);return I(this,n),n}),v(t,"figFont",function(t){const e=g(this);if(void 0===t)return e.activeFont;e.activeFont=t}),v(t,"figText",function(t,e,n,r={}){const i=m(this),s=i.planText(t,r),o=g(this),a=e+function(t,e){return"center"===e?-Math.floor(t/2):"right"===e?-(t-1):0}(s.cols,o.align),l=n+function(t,e,n){return"top"===n?0:"center"===n?-Math.floor(t/2):"bottom"===n?-(t-1):-(e-1)}(s.rows,i.baseline,o.baseline);this.push(),this.translate(a,l,0);for(const t of s.cells){this.push(),this.translate(t.col,t.row,0);const e=p(r.charColor,t),n=p(r.cellColor,t);this.char(t.char),void 0!==e&&w(this,"charColor",e),void 0!==n&&w(this,"cellColor",n),this.point(),this.pop()}this.pop()}),v(t,"figTextWidth",function(t,e={}){return m(this).measureText(t,e).cols}),v(t,"figTextHeight",function(t,e={}){return m(this).measureText(t,e).rows}),v(t,"figTextBounds",function(t,e={}){return m(this).measureText(t,e)}),v(t,"figTextAlign",function(t){const e=g(this);if(void 0===t)return e.align;e.align=t}),v(t,"figTextBaseline",function(t){const e=g(this);if(void 0===t)return e.baseline;e.baseline=t})}function y(t){for(const e of _)delete t[e];!function(t){delete t[d]}(t)}const C={name:h,version:f,install(t,e){L(t)},uninstall(t,e){y(t)}};if(typeof window<"u"){const t=window;t.FigletPlugin=C,t.TextmodeFigFont=c,t.FigFontParser=s,t.FigLayoutEngine=a,t.FigSmushRules=o,t.FIGFONT_REQUIRED_CODEPOINTS=i}export{i as FIGFONT_REQUIRED_CODEPOINTS,s as FigFontParser,a as FigLayoutEngine,o as FigSmushRules,C as FigletPlugin,c as TextmodeFigFont};
|
|
1
|
+
import{color as t}from"textmode.js";var e=class t extends Error{constructor(e,n){super(t.formatMessage(e,n)),this.name="FigletError"}static formatMessage(e,n){return n&&0!==Object.keys(n).length?`${e}\n\nContext:${Object.entries(n).map(([e,n])=>`\n - ${e}: ${t.formatValue(n)}`).join("")}`:e}static formatValue(e){return null===e?"null":void 0===e?"undefined":"string"==typeof e?`"${e}"`:"number"==typeof e||"boolean"==typeof e?String(e):Array.isArray(e)?`[${e.map(e=>t.formatValue(e)).join(", ")}]`:"object"==typeof e?JSON.stringify(e):String(e)}},n=[...Array.from({length:95},(t,e)=>e+32),196,214,220,228,246,252,223],r=class{static t(t){if(0===t.length)throw new e("Cannot parse an empty FIGfont file.");const n=t.replace(/\r\n?/g,"\n").split("\n"),r=n[0];if(!r)throw new e("Missing FIGfont header line.");const i=this.i(r);let s=1+i.commentLines;if(s>n.length)throw new e("FIGfont comment line count exceeds file length.",{commentLines:i.commentLines,totalLines:n.length});const o=/* @__PURE__ */new Map;return s=this.o(n,s,i,o),this.l(n,s,i,o),{header:i,characters:o}}static i(t){const n=t.trim().split(/\s+/),r=n[0]??"";if(r.length<6)throw new e("Invalid FIGfont header token.",{headerToken:r});const i=r.slice(0,5),s=r.slice(5);if("flf2a"!==i)throw new e("Unsupported FIGfont signature.",{signature:i});if(1!==s.length)throw new e("FIGfont hardblank must be a single character.",{hardblank:s});if(n.length<6)throw new e("Incomplete FIGfont header.",{headerLine:t});return{signature:i,hardblank:s,height:this.h(n[1],"height"),baseline:this.h(n[2],"baseline"),maxLength:this.h(n[3],"maxLength"),oldLayout:this.h(n[4],"oldLayout"),commentLines:this.h(n[5],"commentLines"),printDirection:this.h(n[6]??"0","printDirection"),fullLayout:this.h(n[7]??"0","fullLayout"),codetagCount:this.h(n[8]??"0","codetagCount")}}static o(t,e,r,i){let s=e;for(const o of n){const e=this.u(t,s,r.height,o);i.set(o,e),s+=r.height}return s}static l(t,e,n,r){let i=e;for(;i<t.length;){const e=t[i]?.trim()??"";if(0===e.length){i+=1;continue}const s=this._(e);i+=1;const o=this.u(t,i,n.height,s);r.set(s,o),i+=n.height}}static u(t,n,r,i){if(n+r>t.length)throw new e("Unexpected end of FIGfont character data.",{codePoint:i,startIndex:n,height:r,totalLines:t.length});const s=[];let o=0;for(let a=0;a<r;a+=1){const r=t[n+a]??"";if(0===r.length)throw new e("Encountered an empty FIGcharacter row.",{codePoint:i,row:a,startIndex:n});const c=r.at(-1);if(!c)throw new e("Failed to determine FIGcharacter endmark.",{codePoint:i,row:a});const l=r.replace(new RegExp(`${this.escapeForRegExp(c)}+$`),"");s.push(l),o=Math.max(o,l.length)}return{code:i,lines:s,width:o}}static _(t){const n=t.split(/\s+/,1)[0];if(/^[-+]?0x[0-9a-f]+$/i.test(n))return Number.parseInt(n,16);if(/^[-+]?0[0-7]+$/.test(n))return Number.parseInt(n,8);if(/^[-+]?\d+$/.test(n))return Number.parseInt(n,10);throw new e("Invalid FIGfont code tag.",{codetagLine:t})}static h(t,n){if(!/^-?\d+$/.test(t))throw new e("Invalid FIGfont header value.",{field:n,token:t});return Number.parseInt(t,10)}static escapeForRegExp(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}},i=class{static RULE_EQUAL_CHARACTER=1;static RULE_UNDERSCORE=2;static RULE_HIERARCHY=4;static RULE_OPPOSITE_PAIR=8;static RULE_BIG_X=16;static RULE_HARDBLANK=32;static VERTICAL_RULE_EQUAL_CHARACTER=256;static VERTICAL_RULE_UNDERSCORE=512;static VERTICAL_RULE_HIERARCHY=1024;static VERTICAL_RULE_HORIZONTAL_LINE=2048;static VERTICAL_RULE_VERTICAL_LINE_SUPERSMUSH=4096;static p(t){return 0!==t.fullLayout?63&t.fullLayout:t.oldLayout>0?63&t.oldLayout:0}static m(t){return 7936&t.fullLayout}static I(t,e,n,r){return" "===t?e:" "===e?t:0===r?this.L(t,e,n):(0!==(r&this.RULE_EQUAL_CHARACTER)?this.C(t,e,n):null)??(0!==(r&this.RULE_UNDERSCORE)?this.R(t,e):null)??(0!==(r&this.RULE_HIERARCHY)?this.v(t,e):null)??(0!==(r&this.RULE_OPPOSITE_PAIR)?this.A(t,e):null)??(0!==(r&this.RULE_BIG_X)?this.F(t,e):null)??(0!==(r&this.RULE_HARDBLANK)?this.T(t,e,n):null)}static L(t,e,n){return" "===t?e:" "===e?t:e}static U(t,e,n){return" "===t?e:" "===e?t:0===n?this.L(t,e," "):(0!==(n&this.VERTICAL_RULE_EQUAL_CHARACTER)?this.C(t,e," "):null)??(0!==(n&this.VERTICAL_RULE_UNDERSCORE)?this.R(t,e):null)??(0!==(n&this.VERTICAL_RULE_HIERARCHY)?this.v(t,e):null)??(0!==(n&this.VERTICAL_RULE_HORIZONTAL_LINE)?this.S(t,e):null)??(0!==(n&this.VERTICAL_RULE_VERTICAL_LINE_SUPERSMUSH)?this.$(t,e):null)}static C(t,e,n){return t===e&&t!==n?t:null}static R(t,e){const n="|/\\[]{}()<>";return"_"===t&&n.includes(e)?e:"_"===e&&n.includes(t)?t:null}static v(t,e){const n=["|","/\\","[]","{}","()","<>"],r=n.findIndex(e=>e.includes(t)),i=n.findIndex(t=>t.includes(e));return-1===r||-1===i||r===i?null:r>i?t:e}static A(t,e){return["[]","][","{}","}{","()",")("].includes(`${t}${e}`)?"|":null}static F(t,e){const n=`${t}${e}`;return"/\\"===n?"|":"\\/"===n?"Y":"><"===n?"X":null}static T(t,e,n){return t===n&&e===n?n:null}static S(t,e){const n=`${t}${e}`;return"-_"===n||"_-"===n?"=":null}static $(t,e){return"|"===t&&"|"===e?"|":null}},s=class{H;k;M;constructor(t){this.H=t,this.k=i.p(t),this.M=i.m(t)}G(t,e){const n=t.map((t,e)=>({inputIndex:e,inputChar:String.fromCodePoint(t.code)})),r=this.N(t,n,e,0),i=Array.from({length:r.rows},()=>Array.from({length:r.cols},()=>" "));for(const s of r.cells)i[s.row][s.col]=s.char;return i}N(t,e,n,r){if(0===t.length)return{lineIndex:r,cells:[],cols:0,rows:this.H.height};let s=this.O(t[0],e[0],r),o=t[0].width;for(let a=1;a<t.length;a+=1){const c=t[a],l=e[a]??{inputIndex:a,inputChar:String.fromCodePoint(c.code)},h=o-this.V(s,o,c,n),u=Math.max(o,h+c.width),f=s.map(t=>Array.from({length:u},(e,n)=>t[n]));for(let t=0;t<this.H.height;t+=1){const e=c.lines[t]??"",n=f[t];for(let s=0;s<c.width;s+=1){const o=e[s]??" ";if(" "===o)continue;const a=h+s,u=n[a],f=this.P(a,t,s,r,c,l,o);if(!u){n[a]=f;continue}const d=i.I(u.char,o,this.H.hardblank,this.k);n[a]=this.B(u,f,d??o)}}s=f,o=u}return this.D(s,o,r)}j(t,e){if(0===t.length)return{cells:[],lines:[],cols:0,rows:0};let n=this.W(t[0]),r=t[0].cols,s=t[0].rows;const o=[this.q(t[0],0)];for(let a=1;a<t.length;a+=1){const c=t[a],l=s-this.X(n,s,r,c,e),h=Math.max(r,c.cols),u=Math.max(s,l+c.rows),f=Array.from({length:u},(t,e)=>Array.from({length:h},(t,r)=>n[e]?.[r]));for(const t of c.cells){const e=l+t.row,n=t.col,r=f[e]?.[n];if(!r){f[e][n]={...t,row:e};continue}const s=i.U(r.char,t.char,this.M);f[e][n]=this.B(r,{...t,row:e},s??t.char)}n=f,r=h,s=u,o.push(this.q(c,l))}return this.Y(n,r,s,o)}V(t,e,n,r){if("full"===r)return 0;for(let i=e;i>=0;i-=1){let s=!0;for(let o=0;o<this.H.height&&s;o+=1){const a=t[o]??[],c=n.lines[o]??"";for(let t=0;t<i;t+=1){const n=a[e-i+t]?.char??" ",o=c[t]??" ";if(!this.J(n,o,r)){s=!1;break}}}if(s)return i}return 0}J(t,e,n){return" "===t||" "===e||"fitted"!==n&&null!==i.I(t,e,this.H.hardblank,this.k)}O(t,e={inputIndex:0,inputChar:String.fromCodePoint(t.code)},n=0){return Array.from({length:this.H.height},(r,i)=>{const s=t.lines[i]??"";return Array.from({length:t.width},(r,o)=>{const a=s[o]??" ";return" "===a?void 0:this.P(o,i,o,n,t,e,a)})})}P(t,e,n,r,i,s,o){return{char:o,col:t,row:e,inputIndex:s.inputIndex,inputChar:s.inputChar,figCharCode:i.code,subRow:e,subCol:n,lineIndex:r}}B(t,e,n){return n===t.char?t:{...e,char:n}}D(t,e,n){const r=[];for(let i=0;i<this.H.height;i+=1){const s=t[i]??[];for(let t=0;t<e;t+=1){const e=s[t];e&&e.char!==this.H.hardblank&&r.push({...e,col:t,row:i,lineIndex:n})}}return{lineIndex:n,cells:r,cols:e,rows:this.H.height}}X(t,e,n,r,i){if("full"===i)return 0;const s=this.W(r),o=Math.min(e,r.rows),a=Math.max(n,r.cols);for(let c=o;c>=0;c-=1){let n=!0;for(let r=0;r<c&&n;r+=1){const o=t[e-c+r]??[],l=s[r]??[];for(let t=0;t<a;t+=1){const e=o[t]?.char??" ",r=l[t]?.char??" ";if(!this.K(e,r,i)){n=!1;break}}}if(n)return c}return 0}K(t,e,n){return" "===t||" "===e||"fitted"!==n&&null!==i.U(t,e,this.M)}W(t){const e=Array.from({length:t.rows},()=>Array.from({length:t.cols},()=>{}));for(const n of t.cells)e[n.row][n.col]=n;return e}q(t,e){return{...t,cells:t.cells.map(t=>({...t,row:t.row+e}))}}Y(t,e,n,r){const i=[];for(let s=0;s<n;s+=1)for(let n=0;n<e;n+=1){const e=t[s]?.[n];e&&i.push({...e,row:s,col:n})}return{cells:i,lines:r,cols:e,rows:n}}},o=class{Z=/* @__PURE__ */new Set;tt(t){this.Z.add(t)}dispose(){for(const t of this.Z)t();this.Z.clear()}},a=class t extends o{et;H;nt;rt;constructor(t,e,n){super(),this.et=t,this.H=e,this.nt=n,this.rt=new s(e)}static async it(t){const n=await fetch(t);if(!n.ok)throw new e("Failed to load FIGfont file.",{source:String(t),status:n.status,statusText:n.statusText});const r=await n.text();return this.st(this.ot(t),r)}static st(e,n){const i=r.t(n);return new t(e,i.header,i.characters)}getCharacter(t){const e="number"==typeof t?t:Array.from(t)[0]?.codePointAt(0);if(void 0!==e)return c(this.nt.get(e))}planText(t,e={}){const n=e.horizontalLayout??this.defaultLayout,r=e.verticalLayout??this.defaultVerticalLayout,i=this.ct(e.direction),s=this.lt(t).map(t=>this.ht(t,i)).flatMap(t=>this.ut(t,n,e)).map((t,e)=>{const r=this.ft(t);return this.rt.N(r.map(t=>t.figChar),r.map(({inputChar:t,inputIndex:e})=>({inputChar:t,inputIndex:e})),n,e)}),o=this.rt.j(s,r);return{cells:o.cells,lines:o.lines,cols:o.cols,rows:o.rows,direction:i}}renderText(t,e={}){const n=this.planText(t,e),r=Array.from({length:n.rows},()=>Array.from({length:n.cols},()=>" "));for(const i of n.cells)r[i.row][i.col]=i.char;return{grid:r,cols:n.cols,rows:n.rows}}measureText(t,e={}){const n=this.planText(t,e);return{cols:n.cols,rows:n.rows}}get name(){return this.et}get header(){return{...this.H}}get characters(){return new Map(Array.from(this.nt,([t,e])=>[t,c(e)]))}get hardblank(){return this.H.hardblank}get height(){return this.H.height}get baseline(){return this.H.baseline}get defaultLayout(){return 128&this.H.fullLayout?"smushed":64&this.H.fullLayout?"fitted":-1===this.H.oldLayout?"full":0===this.H.oldLayout?"fitted":this.H.oldLayout>0?"smushed":"full"}get defaultPrintDirection(){return 1===this.H.printDirection?"rtl":"ltr"}get defaultVerticalLayout(){return 16384&this.H.fullLayout?"smushed":8192&this.H.fullLayout?"fitted":"full"}static ot(t){const e=t instanceof URL?t.pathname:t,n=(e.split(/[?#]/,1)[0]??e).split("/").filter(Boolean).pop()??"figfont";return n.toLowerCase().endsWith(".flf")?n.slice(0,-4)||"figfont":n}lt(t){const e=[[]];for(const[n,r]of Array.from(t).entries())"\n"!==r?e[e.length-1].push({character:r,inputIndex:n}):e.push([]);return e}ht(t,e){return"rtl"===e?[...t].reverse():t}ft(t){const n=t.map(({character:t,inputIndex:e})=>({figChar:this.getCharacter(t)??this.getCharacter(32),inputChar:t,inputIndex:e})),r=n.find(t=>void 0===t.figChar);if(r)throw new e("FIGfont is missing a required character for layout.",{character:r.inputChar,index:r.inputIndex});return n}ut(t,e,n){const r="number"==typeof n.maxCols&&Number.isFinite(n.maxCols)?Math.floor(n.maxCols):void 0,i=n.wrap??"none";return 0===t.length||!r||r<1||"none"===i?[t]:"char"===i?this.dt(t,e,r):this.gt(t,e,r)}gt(t,e,n){const r=this._t(t);if(!r.some(t=>!t.isWhitespace))return[t];const i=[];let s=[],o=[];for(const a of r){if(a.isWhitespace){s.length>0&&(o=a.characters);continue}const t=0===s.length?a.characters:s.concat(o,a.characters);s.length>0&&this.wt(t,e)>n?(i.push(s),s=a.characters.slice()):s=t,o=[]}return 0===s.length?[[]]:(i.push(s),i)}dt(t,e,n){const r=[];let i=[];for(const s of t){const t=i.concat(s);i.length>0&&this.wt(t,e)>n?(r.push(i),i=[s]):i=t}return 0===i.length?[[]]:(r.push(i),r)}wt(t,e){const n=this.ft(t);return this.rt.N(n.map(t=>t.figChar),n.map(({inputChar:t,inputIndex:e})=>({inputChar:t,inputIndex:e})),e,0).cols}_t(t){const e=[];for(const n of t){const t=/\s/u.test(n.character),r=e[e.length-1];r&&r.isWhitespace===t?r.characters.push(n):e.push({isWhitespace:t,characters:[n]})}return e}ct(t){return"ltr"===t||"rtl"===t?t:this.defaultPrintDirection}};function c(t){if(t)return{...t,lines:[...t.lines]}}var l=Symbol.for("textmode.figlet.state");function h(t){const e=t;return e[l]||(e[l]={activeFont:void 0,align:"left",baseline:"baseline"}),e[l]}var u=["loadFigFont","parseFigFont","figFont","figText","figTextWidth","figTextHeight","figTextBounds","figTextAlign","figTextBaseline"];function f(t,e){if(void 0!==t)return"function"==typeof t?t(e):t}function d(e,n,r){return r instanceof t.TextmodeColor||"string"==typeof r||"number"==typeof r?"charColor"===n?void e.charColor(r):void e.cellColor(r):4===r.length?"charColor"===n?void e.charColor(r[0],r[1],r[2],r[3]):void e.cellColor(r[0],r[1],r[2],r[3]):void("charColor"!==n?e.cellColor(r[0],r[1],r[2]):e.charColor(r[0],r[1],r[2]))}function g(t){const n=h(t).activeFont;if(!n)throw new e("No FIGlet font is active. Call figFont() first.");return n}function _(t,e){t.It?.(e)}function p(t,e,n){Object.defineProperty(t,e,{value:n,writable:!0,configurable:!0,enumerable:!1})}var w={name:"textmode.figlet.js",version:"1.0.3-beta.1",install(t,e){!function(t){p(t,"loadFigFont",async function(t){const e=await a.it(t);return _(this,e),e}),p(t,"parseFigFont",function(t,e){const n=a.st(t,e);return _(this,n),n}),p(t,"figFont",function(t){const e=h(this);if(void 0===t)return e.activeFont;e.activeFont=t}),p(t,"figText",function(t,e,n,r={}){const i=g(this),s=i.planText(t,r),o=h(this),a=e+(c=s.cols,"center"===(l=o.align)?-Math.floor(c/2):"right"===l?-(c-1):0);var c,l;const u=n+(_=s.rows,p=i.baseline,"top"===(w=o.baseline)?0:"center"===w?-Math.floor(_/2):"bottom"===w?-(_-1):-(p-1));var _,p,w;this.push(),this.translate(a,u,0);for(const h of s.cells){this.push(),this.translate(h.col,h.row,0);const t=f(r.charColor,h),e=f(r.cellColor,h);this.char(h.char),void 0!==t&&d(this,"charColor",t),void 0!==e&&d(this,"cellColor",e),this.point(),this.pop()}this.pop()}),p(t,"figTextWidth",function(t,e={}){return g(this).measureText(t,e).cols}),p(t,"figTextHeight",function(t,e={}){return g(this).measureText(t,e).rows}),p(t,"figTextBounds",function(t,e={}){return g(this).measureText(t,e)}),p(t,"figTextAlign",function(t){const e=h(this);if(void 0===t)return e.align;e.align=t}),p(t,"figTextBaseline",function(t){const e=h(this);if(void 0===t)return e.baseline;e.baseline=t})}(t)},uninstall(t,e){!function(t){for(const e of u)delete t[e];!function(t){delete t[l]}(t)}(t)}};if("undefined"!=typeof window){const t=window;t.FigletPlugin=w,t.TextmodeFigFont=a,t.FigFontParser=r,t.FigLayoutEngine=s,t.FigSmushRules=i,t.FIGFONT_REQUIRED_CODEPOINTS=n}export{n as FIGFONT_REQUIRED_CODEPOINTS,r as FigFontParser,s as FigLayoutEngine,i as FigSmushRules,w as FigletPlugin,a as TextmodeFigFont};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&typeof module<"u"?e(exports,require("textmode.js")):"function"==typeof define&&define.amd?define(["exports","textmode.js"],e):e((t=typeof globalThis<"u"?globalThis:t||self).TextmodeFiglet={},t.textmode)}(this,function(t,e){"use strict";var n=Object.defineProperty,r=(t,e,r)=>((t,e,r)=>e in t?n(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r)(t,"symbol"!=typeof e?e+"":e,r);class i extends Error{constructor(t,e){super(i.formatMessage(t,e)),this.name="FigletError"}static formatMessage(t,e){if(!e||0===Object.keys(e).length)return t;return`${t}\n\nContext:${Object.entries(e).map(([t,e])=>`\n - ${t}: ${i.formatValue(e)}`).join("")}`}static formatValue(t){return null===t?"null":void 0===t?"undefined":"string"==typeof t?`"${t}"`:"number"==typeof t||"boolean"==typeof t?String(t):Array.isArray(t)?`[${t.map(t=>i.formatValue(t)).join(", ")}]`:"object"==typeof t?JSON.stringify(t):String(t)}}const s=[...Array.from({length:95},(t,e)=>e+32),196,214,220,228,246,252,223];class o{static t(t){if(0===t.length)throw new i("Cannot parse an empty FIGfont file.");const e=t.replace(/\r\n?/g,"\n").split("\n"),n=e[0];if(!n)throw new i("Missing FIGfont header line.");const r=this.i(n);let s=1+r.commentLines;if(s>e.length)throw new i("FIGfont comment line count exceeds file length.",{commentLines:r.commentLines,totalLines:e.length});const o=new Map;return s=this.o(e,s,r,o),this.l(e,s,r,o),{header:r,characters:o}}static i(t){const e=t.trim().split(/\s+/),n=e[0]??"";if(n.length<6)throw new i("Invalid FIGfont header token.",{headerToken:n});const r=n.slice(0,5),s=n.slice(5);if("flf2a"!==r)throw new i("Unsupported FIGfont signature.",{signature:r});if(1!==s.length)throw new i("FIGfont hardblank must be a single character.",{hardblank:s});if(e.length<6)throw new i("Incomplete FIGfont header.",{headerLine:t});return{signature:r,hardblank:s,height:this.u(e[1],"height"),baseline:this.u(e[2],"baseline"),maxLength:this.u(e[3],"maxLength"),oldLayout:this.u(e[4],"oldLayout"),commentLines:this.u(e[5],"commentLines"),printDirection:this.u(e[6]??"0","printDirection"),fullLayout:this.u(e[7]??"0","fullLayout"),codetagCount:this.u(e[8]??"0","codetagCount")}}static o(t,e,n,r){let i=e;for(const e of s){const s=this.h(t,i,n.height,e);r.set(e,s),i+=n.height}return i}static l(t,e,n,r){var i;let s=e;for(;s<t.length;){const e=(null==(i=t[s])?void 0:i.trim())??"";if(0===e.length){s+=1;continue}const o=this.p(e);s+=1;const a=this.h(t,s,n.height,o);r.set(o,a),s+=n.height}}static h(t,e,n,r){if(e+n>t.length)throw new i("Unexpected end of FIGfont character data.",{codePoint:r,startIndex:e,height:n,totalLines:t.length});const s=[];let o=0;for(let a=0;a<n;a+=1){const n=t[e+a]??"";if(0===n.length)throw new i("Encountered an empty FIGcharacter row.",{codePoint:r,row:a,startIndex:e});const l=n.at(-1);if(!l)throw new i("Failed to determine FIGcharacter endmark.",{codePoint:r,row:a});const c=n.replace(new RegExp(`${this.escapeForRegExp(l)}+$`),"");s.push(c),o=Math.max(o,c.length)}return{code:r,lines:s,width:o}}static p(t){const e=t.split(/\s+/,1)[0];if(/^[-+]?0x[0-9a-f]+$/i.test(e))return Number.parseInt(e,16);if(/^[-+]?0[0-7]+$/.test(e))return Number.parseInt(e,8);if(/^[-+]?\d+$/.test(e))return Number.parseInt(e,10);throw new i("Invalid FIGfont code tag.",{codetagLine:t})}static u(t,e){if(!/^-?\d+$/.test(t))throw new i("Invalid FIGfont header value.",{field:e,token:t});return Number.parseInt(t,10)}static escapeForRegExp(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}}class a{static _(t){return 0!==t.fullLayout?63&t.fullLayout:t.oldLayout>0?63&t.oldLayout:0}static m(t){return 7936&t.fullLayout}static I(t,e,n,r){return" "===t?e:" "===e?t:0===r?this.v(t,e,n):(0!==(r&this.RULE_EQUAL_CHARACTER)?this.L(t,e,n):null)??(0!==(r&this.RULE_UNDERSCORE)?this.C(t,e):null)??(0!==(r&this.RULE_HIERARCHY)?this.R(t,e):null)??(0!==(r&this.RULE_OPPOSITE_PAIR)?this.A(t,e):null)??(0!==(r&this.RULE_BIG_X)?this.F(t,e):null)??(0!==(r&this.RULE_HARDBLANK)?this.T(t,e,n):null)}static v(t,e,n){return" "===t?e:" "===e?t:e}static U(t,e,n){return" "===t?e:" "===e?t:0===n?this.v(t,e," "):(0!==(n&this.VERTICAL_RULE_EQUAL_CHARACTER)?this.L(t,e," "):null)??(0!==(n&this.VERTICAL_RULE_UNDERSCORE)?this.C(t,e):null)??(0!==(n&this.VERTICAL_RULE_HIERARCHY)?this.R(t,e):null)??(0!==(n&this.VERTICAL_RULE_HORIZONTAL_LINE)?this.S(t,e):null)??(0!==(n&this.VERTICAL_RULE_VERTICAL_LINE_SUPERSMUSH)?this.$(t,e):null)}static L(t,e,n){return t===e&&t!==n?t:null}static C(t,e){const n="|/\\[]{}()<>";return"_"===t&&n.includes(e)?e:"_"===e&&n.includes(t)?t:null}static R(t,e){const n=["|","/\\","[]","{}","()","<>"],r=n.findIndex(e=>e.includes(t)),i=n.findIndex(t=>t.includes(e));return-1===r||-1===i||r===i?null:r>i?t:e}static A(t,e){return["[]","][","{}","}{","()",")("].includes(`${t}${e}`)?"|":null}static F(t,e){const n=`${t}${e}`;return"/\\"===n?"|":"\\/"===n?"Y":"><"===n?"X":null}static T(t,e,n){return t===n&&e===n?n:null}static S(t,e){const n=`${t}${e}`;return"-_"===n||"_-"===n?"=":null}static $(t,e){return"|"===t&&"|"===e?"|":null}}r(a,"RULE_EQUAL_CHARACTER",1),r(a,"RULE_UNDERSCORE",2),r(a,"RULE_HIERARCHY",4),r(a,"RULE_OPPOSITE_PAIR",8),r(a,"RULE_BIG_X",16),r(a,"RULE_HARDBLANK",32),r(a,"VERTICAL_RULE_EQUAL_CHARACTER",256),r(a,"VERTICAL_RULE_UNDERSCORE",512),r(a,"VERTICAL_RULE_HIERARCHY",1024),r(a,"VERTICAL_RULE_HORIZONTAL_LINE",2048),r(a,"VERTICAL_RULE_VERTICAL_LINE_SUPERSMUSH",4096);class l{constructor(t){r(this,"_header"),r(this,"_horizontalRuleMask"),r(this,"_verticalRuleMask"),this.H=t,this.M=a._(t),this.k=a.m(t)}G(t,e){const n=t.map((t,e)=>({inputIndex:e,inputChar:String.fromCodePoint(t.code)})),r=this.O(t,n,e,0),i=Array.from({length:r.rows},()=>Array.from({length:r.cols},()=>" "));for(const t of r.cells)i[t.row][t.col]=t.char;return i}O(t,e,n,r){if(0===t.length)return{lineIndex:r,cells:[],cols:0,rows:this.H.height};let i=this.N(t[0],e[0],r),s=t[0].width;for(let o=1;o<t.length;o+=1){const l=t[o],c=e[o]??{inputIndex:o,inputChar:String.fromCodePoint(l.code)},u=s-this.V(i,s,l,n),h=Math.max(s,u+l.width),f=i.map(t=>Array.from({length:h},(e,n)=>t[n]));for(let t=0;t<this.H.height;t+=1){const e=l.lines[t]??"",n=f[t];for(let i=0;i<l.width;i+=1){const s=e[i]??" ";if(" "===s)continue;const o=u+i,h=n[o],f=this.P(o,t,i,r,l,c,s);if(!h){n[o]=f;continue}const d=a.I(h.char,s,this.H.hardblank,this.M);n[o]=this.B(h,f,d??s)}}i=f,s=h}return this.j(i,s,r)}D(t,e){var n;if(0===t.length)return{cells:[],lines:[],cols:0,rows:0};let r=this.W(t[0]),i=t[0].cols,s=t[0].rows;const o=[this.q(t[0],0)];for(let l=1;l<t.length;l+=1){const c=t[l],u=s-this.X(r,s,i,c,e),h=Math.max(i,c.cols),f=Math.max(s,u+c.rows),d=Array.from({length:f},(t,e)=>Array.from({length:h},(t,n)=>{var i;return null==(i=r[e])?void 0:i[n]}));for(const t of c.cells){const e=u+t.row,r=t.col,i=null==(n=d[e])?void 0:n[r];if(!i){d[e][r]={...t,row:e};continue}const s=a.U(i.char,t.char,this.k);d[e][r]=this.B(i,{...t,row:e},s??t.char)}r=d,i=h,s=f,o.push(this.q(c,u))}return this.Y(r,i,s,o)}V(t,e,n,r){var i;if("full"===r)return 0;for(let s=e;s>=0;s-=1){let o=!0;for(let a=0;a<this.H.height&&o;a+=1){const l=t[a]??[],c=n.lines[a]??"";for(let t=0;t<s;t+=1){const n=(null==(i=l[e-s+t])?void 0:i.char)??" ",a=c[t]??" ";if(!this.J(n,a,r)){o=!1;break}}}if(o)return s}return 0}J(t,e,n){return" "===t||" "===e||"fitted"!==n&&null!==a.I(t,e,this.H.hardblank,this.M)}N(t,e={inputIndex:0,inputChar:String.fromCodePoint(t.code)},n=0){return Array.from({length:this.H.height},(r,i)=>{const s=t.lines[i]??"";return Array.from({length:t.width},(r,o)=>{const a=s[o]??" ";return" "===a?void 0:this.P(o,i,o,n,t,e,a)})})}P(t,e,n,r,i,s,o){return{char:o,col:t,row:e,inputIndex:s.inputIndex,inputChar:s.inputChar,figCharCode:i.code,subRow:e,subCol:n,lineIndex:r}}B(t,e,n){return n===t.char?t:{...e,char:n}}j(t,e,n){const r=[];for(let i=0;i<this.H.height;i+=1){const s=t[i]??[];for(let t=0;t<e;t+=1){const e=s[t];!e||e.char===this.H.hardblank||r.push({...e,col:t,row:i,lineIndex:n})}}return{lineIndex:n,cells:r,cols:e,rows:this.H.height}}X(t,e,n,r,i){var s,o;if("full"===i)return 0;const a=this.W(r),l=Math.min(e,r.rows),c=Math.max(n,r.cols);for(let n=l;n>=0;n-=1){let r=!0;for(let l=0;l<n&&r;l+=1){const u=t[e-n+l]??[],h=a[l]??[];for(let t=0;t<c;t+=1){const e=(null==(s=u[t])?void 0:s.char)??" ",n=(null==(o=h[t])?void 0:o.char)??" ";if(!this.K(e,n,i)){r=!1;break}}}if(r)return n}return 0}K(t,e,n){return" "===t||" "===e||"fitted"!==n&&null!==a.U(t,e,this.k)}W(t){const e=Array.from({length:t.rows},()=>Array.from({length:t.cols},()=>{}));for(const n of t.cells)e[n.row][n.col]=n;return e}q(t,e){return{...t,cells:t.cells.map(t=>({...t,row:t.row+e}))}}Y(t,e,n,r){var i;const s=[];for(let r=0;r<n;r+=1)for(let n=0;n<e;n+=1){const e=null==(i=t[r])?void 0:i[n];e&&s.push({...e,row:r,col:n})}return{cells:s,lines:r,cols:e,rows:n}}}class c{constructor(){r(this,"_onDisposeCallbacks",new Set)}Z(t){this.tt.add(t)}dispose(){for(const t of this.tt)t();this.tt.clear()}}class u extends c{constructor(t,e,n){super(),r(this,"_name"),r(this,"_header"),r(this,"_characters"),r(this,"_layoutEngine"),this.et=t,this.H=e,this.nt=n,this.rt=new l(e)}static async it(t){const e=await fetch(t);if(!e.ok)throw new i("Failed to load FIGfont file.",{source:String(t),status:e.status,statusText:e.statusText});const n=await e.text();return this.st(this.ot(t),n)}static st(t,e){const n=o.t(e);return new u(t,n.header,n.characters)}getCharacter(t){var e;const n="number"==typeof t?t:null==(e=Array.from(t)[0])?void 0:e.codePointAt(0);if(void 0!==n)return h(this.nt.get(n))}planText(t,e={}){const n=e.horizontalLayout??this.defaultLayout,r=e.verticalLayout??this.defaultVerticalLayout,i=this.lt(e.direction),s=this.ct(t).map(t=>this.ut(t,i)).flatMap(t=>this.ht(t,n,e)).map((t,e)=>{const r=this.ft(t);return this.rt.O(r.map(t=>t.figChar),r.map(({inputChar:t,inputIndex:e})=>({inputChar:t,inputIndex:e})),n,e)}),o=this.rt.D(s,r);return{cells:o.cells,lines:o.lines,cols:o.cols,rows:o.rows,direction:i}}renderText(t,e={}){const n=this.planText(t,e),r=Array.from({length:n.rows},()=>Array.from({length:n.cols},()=>" "));for(const t of n.cells)r[t.row][t.col]=t.char;return{grid:r,cols:n.cols,rows:n.rows}}measureText(t,e={}){const n=this.planText(t,e);return{cols:n.cols,rows:n.rows}}get name(){return this.et}get header(){return{...this.H}}get characters(){return new Map(Array.from(this.nt,([t,e])=>[t,h(e)]))}get hardblank(){return this.H.hardblank}get height(){return this.H.height}get baseline(){return this.H.baseline}get defaultLayout(){return 128&this.H.fullLayout?"smushed":64&this.H.fullLayout?"fitted":-1===this.H.oldLayout?"full":0===this.H.oldLayout?"fitted":this.H.oldLayout>0?"smushed":"full"}get defaultPrintDirection(){return 1===this.H.printDirection?"rtl":"ltr"}get defaultVerticalLayout(){return 16384&this.H.fullLayout?"smushed":8192&this.H.fullLayout?"fitted":"full"}static ot(t){const e=t instanceof URL?t.pathname:t,n=(e.split(/[?#]/,1)[0]??e).split("/").filter(Boolean).pop()??"figfont";return n.toLowerCase().endsWith(".flf")?n.slice(0,-4)||"figfont":n}ct(t){const e=[[]];for(const[n,r]of Array.from(t).entries())"\n"!==r?e[e.length-1].push({character:r,inputIndex:n}):e.push([]);return e}ut(t,e){return"rtl"===e?[...t].reverse():t}ft(t){const e=t.map(({character:t,inputIndex:e})=>({figChar:this.getCharacter(t)??this.getCharacter(32),inputChar:t,inputIndex:e})),n=e.find(t=>void 0===t.figChar);if(n)throw new i("FIGfont is missing a required character for layout.",{character:n.inputChar,index:n.inputIndex});return e}ht(t,e,n){const r="number"==typeof n.maxCols&&Number.isFinite(n.maxCols)?Math.floor(n.maxCols):void 0,i=n.wrap??"none";return 0===t.length||!r||r<1||"none"===i?[t]:"char"===i?this.dt(t,e,r):this.gt(t,e,r)}gt(t,e,n){const r=this._t(t);if(!r.some(t=>!t.isWhitespace))return[t];const i=[];let s=[],o=[];for(const t of r){if(t.isWhitespace){s.length>0&&(o=t.characters);continue}const r=0===s.length?t.characters:s.concat(o,t.characters);s.length>0&&this.wt(r,e)>n?(i.push(s),s=t.characters.slice()):s=r,o=[]}return 0===s.length?[[]]:(i.push(s),i)}dt(t,e,n){const r=[];let i=[];for(const s of t){const t=i.concat(s);i.length>0&&this.wt(t,e)>n?(r.push(i),i=[s]):i=t}return 0===i.length?[[]]:(r.push(i),r)}wt(t,e){const n=this.ft(t);return this.rt.O(n.map(t=>t.figChar),n.map(({inputChar:t,inputIndex:e})=>({inputChar:t,inputIndex:e})),e,0).cols}_t(t){const e=[];for(const n of t){const t=/\s/u.test(n.character),r=e[e.length-1];r&&r.isWhitespace===t?r.characters.push(n):e.push({isWhitespace:t,characters:[n]})}return e}lt(t){return"ltr"===t||"rtl"===t?t:this.defaultPrintDirection}}function h(t){if(t)return{...t,lines:[...t.lines]}}const f="textmode.figlet.js",d="1.0.1",g=Symbol.for("textmode.figlet.state");function p(t){const e=t;return e[g]||(e[g]={activeFont:void 0,align:"left",baseline:"baseline"}),e[g]}const _=["loadFigFont","parseFigFont","figFont","figText","figTextWidth","figTextHeight","figTextBounds","figTextAlign","figTextBaseline"];function w(t,e){if(void 0!==t)return"function"==typeof t?t(e):t}function m(t,n,r){return r instanceof e.color.TextmodeColor||"string"==typeof r||"number"==typeof r?"charColor"===n?void t.charColor(r):void t.cellColor(r):4===r.length?"charColor"===n?void t.charColor(r[0],r[1],r[2],r[3]):void t.cellColor(r[0],r[1],r[2],r[3]):void("charColor"!==n?t.cellColor(r[0],r[1],r[2]):t.charColor(r[0],r[1],r[2]))}function I(t){const e=p(t).activeFont;if(!e)throw new i("No FIGlet font is active. Call figFont() first.");return e}function y(t,e){var n;null==(n=t.It)||n.call(t,e)}function v(t,e,n){Object.defineProperty(t,e,{value:n,writable:!0,configurable:!0,enumerable:!1})}function x(t){v(t,"loadFigFont",async function(t){const e=await u.it(t);return y(this,e),e}),v(t,"parseFigFont",function(t,e){const n=u.st(t,e);return y(this,n),n}),v(t,"figFont",function(t){const e=p(this);if(void 0===t)return e.activeFont;e.activeFont=t}),v(t,"figText",function(t,e,n,r={}){const i=I(this),s=i.planText(t,r),o=p(this),a=e+function(t,e){return"center"===e?-Math.floor(t/2):"right"===e?-(t-1):0}(s.cols,o.align),l=n+function(t,e,n){return"top"===n?0:"center"===n?-Math.floor(t/2):"bottom"===n?-(t-1):-(e-1)}(s.rows,i.baseline,o.baseline);this.push(),this.translate(a,l,0);for(const t of s.cells){this.push(),this.translate(t.col,t.row,0);const e=w(r.charColor,t),n=w(r.cellColor,t);this.char(t.char),void 0!==e&&m(this,"charColor",e),void 0!==n&&m(this,"cellColor",n),this.point(),this.pop()}this.pop()}),v(t,"figTextWidth",function(t,e={}){return I(this).measureText(t,e).cols}),v(t,"figTextHeight",function(t,e={}){return I(this).measureText(t,e).rows}),v(t,"figTextBounds",function(t,e={}){return I(this).measureText(t,e)}),v(t,"figTextAlign",function(t){const e=p(this);if(void 0===t)return e.align;e.align=t}),v(t,"figTextBaseline",function(t){const e=p(this);if(void 0===t)return e.baseline;e.baseline=t})}function L(t){for(const e of _)delete t[e];!function(t){delete t[g]}(t)}const C={name:f,version:d,install(t,e){x(t)},uninstall(t,e){L(t)}};if(typeof window<"u"){const t=window;t.FigletPlugin=C,t.TextmodeFigFont=u,t.FigFontParser=o,t.FigLayoutEngine=l,t.FigSmushRules=a,t.FIGFONT_REQUIRED_CODEPOINTS=s}t.FIGFONT_REQUIRED_CODEPOINTS=s,t.FigFontParser=o,t.FigLayoutEngine=l,t.FigSmushRules=a,t.FigletPlugin=C,t.TextmodeFigFont=u,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("textmode.js")):"function"==typeof define&&define.amd?define(["exports","textmode.js"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).TextmodeFiglet={},t.textmode)}(this,function(t,e){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});var n=class t extends Error{constructor(e,n){super(t.formatMessage(e,n)),this.name="FigletError"}static formatMessage(e,n){return n&&0!==Object.keys(n).length?`${e}\n\nContext:${Object.entries(n).map(([e,n])=>`\n - ${e}: ${t.formatValue(n)}`).join("")}`:e}static formatValue(e){return null===e?"null":void 0===e?"undefined":"string"==typeof e?`"${e}"`:"number"==typeof e||"boolean"==typeof e?String(e):Array.isArray(e)?`[${e.map(e=>t.formatValue(e)).join(", ")}]`:"object"==typeof e?JSON.stringify(e):String(e)}},r=[...Array.from({length:95},(t,e)=>e+32),196,214,220,228,246,252,223],i=class{static t(t){if(0===t.length)throw new n("Cannot parse an empty FIGfont file.");const e=t.replace(/\r\n?/g,"\n").split("\n"),r=e[0];if(!r)throw new n("Missing FIGfont header line.");const i=this.i(r);let s=1+i.commentLines;if(s>e.length)throw new n("FIGfont comment line count exceeds file length.",{commentLines:i.commentLines,totalLines:e.length});const o=new Map;return s=this.o(e,s,i,o),this.l(e,s,i,o),{header:i,characters:o}}static i(t){const e=t.trim().split(/\s+/),r=e[0]??"";if(r.length<6)throw new n("Invalid FIGfont header token.",{headerToken:r});const i=r.slice(0,5),s=r.slice(5);if("flf2a"!==i)throw new n("Unsupported FIGfont signature.",{signature:i});if(1!==s.length)throw new n("FIGfont hardblank must be a single character.",{hardblank:s});if(e.length<6)throw new n("Incomplete FIGfont header.",{headerLine:t});return{signature:i,hardblank:s,height:this.u(e[1],"height"),baseline:this.u(e[2],"baseline"),maxLength:this.u(e[3],"maxLength"),oldLayout:this.u(e[4],"oldLayout"),commentLines:this.u(e[5],"commentLines"),printDirection:this.u(e[6]??"0","printDirection"),fullLayout:this.u(e[7]??"0","fullLayout"),codetagCount:this.u(e[8]??"0","codetagCount")}}static o(t,e,n,i){let s=e;for(const o of r){const e=this.h(t,s,n.height,o);i.set(o,e),s+=n.height}return s}static l(t,e,n,r){let i=e;for(;i<t.length;){const e=t[i]?.trim()??"";if(0===e.length){i+=1;continue}const s=this.p(e);i+=1;const o=this.h(t,i,n.height,s);r.set(s,o),i+=n.height}}static h(t,e,r,i){if(e+r>t.length)throw new n("Unexpected end of FIGfont character data.",{codePoint:i,startIndex:e,height:r,totalLines:t.length});const s=[];let o=0;for(let a=0;a<r;a+=1){const r=t[e+a]??"";if(0===r.length)throw new n("Encountered an empty FIGcharacter row.",{codePoint:i,row:a,startIndex:e});const c=r.at(-1);if(!c)throw new n("Failed to determine FIGcharacter endmark.",{codePoint:i,row:a});const l=r.replace(new RegExp(`${this.escapeForRegExp(c)}+$`),"");s.push(l),o=Math.max(o,l.length)}return{code:i,lines:s,width:o}}static p(t){const e=t.split(/\s+/,1)[0];if(/^[-+]?0x[0-9a-f]+$/i.test(e))return Number.parseInt(e,16);if(/^[-+]?0[0-7]+$/.test(e))return Number.parseInt(e,8);if(/^[-+]?\d+$/.test(e))return Number.parseInt(e,10);throw new n("Invalid FIGfont code tag.",{codetagLine:t})}static u(t,e){if(!/^-?\d+$/.test(t))throw new n("Invalid FIGfont header value.",{field:e,token:t});return Number.parseInt(t,10)}static escapeForRegExp(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}},s=class{static RULE_EQUAL_CHARACTER=1;static RULE_UNDERSCORE=2;static RULE_HIERARCHY=4;static RULE_OPPOSITE_PAIR=8;static RULE_BIG_X=16;static RULE_HARDBLANK=32;static VERTICAL_RULE_EQUAL_CHARACTER=256;static VERTICAL_RULE_UNDERSCORE=512;static VERTICAL_RULE_HIERARCHY=1024;static VERTICAL_RULE_HORIZONTAL_LINE=2048;static VERTICAL_RULE_VERTICAL_LINE_SUPERSMUSH=4096;static _(t){return 0!==t.fullLayout?63&t.fullLayout:t.oldLayout>0?63&t.oldLayout:0}static m(t){return 7936&t.fullLayout}static I(t,e,n,r){return" "===t?e:" "===e?t:0===r?this.L(t,e,n):(0!==(r&this.RULE_EQUAL_CHARACTER)?this.C(t,e,n):null)??(0!==(r&this.RULE_UNDERSCORE)?this.R(t,e):null)??(0!==(r&this.RULE_HIERARCHY)?this.v(t,e):null)??(0!==(r&this.RULE_OPPOSITE_PAIR)?this.A(t,e):null)??(0!==(r&this.RULE_BIG_X)?this.F(t,e):null)??(0!==(r&this.RULE_HARDBLANK)?this.T(t,e,n):null)}static L(t,e,n){return" "===t?e:" "===e?t:e}static U(t,e,n){return" "===t?e:" "===e?t:0===n?this.L(t,e," "):(0!==(n&this.VERTICAL_RULE_EQUAL_CHARACTER)?this.C(t,e," "):null)??(0!==(n&this.VERTICAL_RULE_UNDERSCORE)?this.R(t,e):null)??(0!==(n&this.VERTICAL_RULE_HIERARCHY)?this.v(t,e):null)??(0!==(n&this.VERTICAL_RULE_HORIZONTAL_LINE)?this.S(t,e):null)??(0!==(n&this.VERTICAL_RULE_VERTICAL_LINE_SUPERSMUSH)?this.$(t,e):null)}static C(t,e,n){return t===e&&t!==n?t:null}static R(t,e){const n="|/\\[]{}()<>";return"_"===t&&n.includes(e)?e:"_"===e&&n.includes(t)?t:null}static v(t,e){const n=["|","/\\","[]","{}","()","<>"],r=n.findIndex(e=>e.includes(t)),i=n.findIndex(t=>t.includes(e));return-1===r||-1===i||r===i?null:r>i?t:e}static A(t,e){return["[]","][","{}","}{","()",")("].includes(`${t}${e}`)?"|":null}static F(t,e){const n=`${t}${e}`;return"/\\"===n?"|":"\\/"===n?"Y":"><"===n?"X":null}static T(t,e,n){return t===n&&e===n?n:null}static S(t,e){const n=`${t}${e}`;return"-_"===n||"_-"===n?"=":null}static $(t,e){return"|"===t&&"|"===e?"|":null}},o=class{H;M;k;constructor(t){this.H=t,this.M=s._(t),this.k=s.m(t)}G(t,e){const n=t.map((t,e)=>({inputIndex:e,inputChar:String.fromCodePoint(t.code)})),r=this.O(t,n,e,0),i=Array.from({length:r.rows},()=>Array.from({length:r.cols},()=>" "));for(const s of r.cells)i[s.row][s.col]=s.char;return i}O(t,e,n,r){if(0===t.length)return{lineIndex:r,cells:[],cols:0,rows:this.H.height};let i=this.N(t[0],e[0],r),o=t[0].width;for(let a=1;a<t.length;a+=1){const c=t[a],l=e[a]??{inputIndex:a,inputChar:String.fromCodePoint(c.code)},u=o-this.V(i,o,c,n),h=Math.max(o,u+c.width),f=i.map(t=>Array.from({length:h},(e,n)=>t[n]));for(let t=0;t<this.H.height;t+=1){const e=c.lines[t]??"",n=f[t];for(let i=0;i<c.width;i+=1){const o=e[i]??" ";if(" "===o)continue;const a=u+i,h=n[a],f=this.P(a,t,i,r,c,l,o);if(!h){n[a]=f;continue}const d=s.I(h.char,o,this.H.hardblank,this.M);n[a]=this.B(h,f,d??o)}}i=f,o=h}return this.D(i,o,r)}j(t,e){if(0===t.length)return{cells:[],lines:[],cols:0,rows:0};let n=this.W(t[0]),r=t[0].cols,i=t[0].rows;const o=[this.q(t[0],0)];for(let a=1;a<t.length;a+=1){const c=t[a],l=i-this.X(n,i,r,c,e),u=Math.max(r,c.cols),h=Math.max(i,l+c.rows),f=Array.from({length:h},(t,e)=>Array.from({length:u},(t,r)=>n[e]?.[r]));for(const t of c.cells){const e=l+t.row,n=t.col,r=f[e]?.[n];if(!r){f[e][n]={...t,row:e};continue}const i=s.U(r.char,t.char,this.k);f[e][n]=this.B(r,{...t,row:e},i??t.char)}n=f,r=u,i=h,o.push(this.q(c,l))}return this.Y(n,r,i,o)}V(t,e,n,r){if("full"===r)return 0;for(let i=e;i>=0;i-=1){let s=!0;for(let o=0;o<this.H.height&&s;o+=1){const a=t[o]??[],c=n.lines[o]??"";for(let t=0;t<i;t+=1){const n=a[e-i+t]?.char??" ",o=c[t]??" ";if(!this.J(n,o,r)){s=!1;break}}}if(s)return i}return 0}J(t,e,n){return" "===t||" "===e||"fitted"!==n&&null!==s.I(t,e,this.H.hardblank,this.M)}N(t,e={inputIndex:0,inputChar:String.fromCodePoint(t.code)},n=0){return Array.from({length:this.H.height},(r,i)=>{const s=t.lines[i]??"";return Array.from({length:t.width},(r,o)=>{const a=s[o]??" ";return" "===a?void 0:this.P(o,i,o,n,t,e,a)})})}P(t,e,n,r,i,s,o){return{char:o,col:t,row:e,inputIndex:s.inputIndex,inputChar:s.inputChar,figCharCode:i.code,subRow:e,subCol:n,lineIndex:r}}B(t,e,n){return n===t.char?t:{...e,char:n}}D(t,e,n){const r=[];for(let i=0;i<this.H.height;i+=1){const s=t[i]??[];for(let t=0;t<e;t+=1){const e=s[t];e&&e.char!==this.H.hardblank&&r.push({...e,col:t,row:i,lineIndex:n})}}return{lineIndex:n,cells:r,cols:e,rows:this.H.height}}X(t,e,n,r,i){if("full"===i)return 0;const s=this.W(r),o=Math.min(e,r.rows),a=Math.max(n,r.cols);for(let c=o;c>=0;c-=1){let n=!0;for(let r=0;r<c&&n;r+=1){const o=t[e-c+r]??[],l=s[r]??[];for(let t=0;t<a;t+=1){const e=o[t]?.char??" ",r=l[t]?.char??" ";if(!this.K(e,r,i)){n=!1;break}}}if(n)return c}return 0}K(t,e,n){return" "===t||" "===e||"fitted"!==n&&null!==s.U(t,e,this.k)}W(t){const e=Array.from({length:t.rows},()=>Array.from({length:t.cols},()=>{}));for(const n of t.cells)e[n.row][n.col]=n;return e}q(t,e){return{...t,cells:t.cells.map(t=>({...t,row:t.row+e}))}}Y(t,e,n,r){const i=[];for(let s=0;s<n;s+=1)for(let n=0;n<e;n+=1){const e=t[s]?.[n];e&&i.push({...e,row:s,col:n})}return{cells:i,lines:r,cols:e,rows:n}}},a=class{Z=new Set;tt(t){this.Z.add(t)}dispose(){for(const t of this.Z)t();this.Z.clear()}},c=class t extends a{et;H;nt;rt;constructor(t,e,n){super(),this.et=t,this.H=e,this.nt=n,this.rt=new o(e)}static async it(t){const e=await fetch(t);if(!e.ok)throw new n("Failed to load FIGfont file.",{source:String(t),status:e.status,statusText:e.statusText});const r=await e.text();return this.st(this.ot(t),r)}static st(e,n){const r=i.t(n);return new t(e,r.header,r.characters)}getCharacter(t){const e="number"==typeof t?t:Array.from(t)[0]?.codePointAt(0);if(void 0!==e)return l(this.nt.get(e))}planText(t,e={}){const n=e.horizontalLayout??this.defaultLayout,r=e.verticalLayout??this.defaultVerticalLayout,i=this.ct(e.direction),s=this.lt(t).map(t=>this.ut(t,i)).flatMap(t=>this.ht(t,n,e)).map((t,e)=>{const r=this.ft(t);return this.rt.O(r.map(t=>t.figChar),r.map(({inputChar:t,inputIndex:e})=>({inputChar:t,inputIndex:e})),n,e)}),o=this.rt.j(s,r);return{cells:o.cells,lines:o.lines,cols:o.cols,rows:o.rows,direction:i}}renderText(t,e={}){const n=this.planText(t,e),r=Array.from({length:n.rows},()=>Array.from({length:n.cols},()=>" "));for(const i of n.cells)r[i.row][i.col]=i.char;return{grid:r,cols:n.cols,rows:n.rows}}measureText(t,e={}){const n=this.planText(t,e);return{cols:n.cols,rows:n.rows}}get name(){return this.et}get header(){return{...this.H}}get characters(){return new Map(Array.from(this.nt,([t,e])=>[t,l(e)]))}get hardblank(){return this.H.hardblank}get height(){return this.H.height}get baseline(){return this.H.baseline}get defaultLayout(){return 128&this.H.fullLayout?"smushed":64&this.H.fullLayout?"fitted":-1===this.H.oldLayout?"full":0===this.H.oldLayout?"fitted":this.H.oldLayout>0?"smushed":"full"}get defaultPrintDirection(){return 1===this.H.printDirection?"rtl":"ltr"}get defaultVerticalLayout(){return 16384&this.H.fullLayout?"smushed":8192&this.H.fullLayout?"fitted":"full"}static ot(t){const e=t instanceof URL?t.pathname:t,n=(e.split(/[?#]/,1)[0]??e).split("/").filter(Boolean).pop()??"figfont";return n.toLowerCase().endsWith(".flf")?n.slice(0,-4)||"figfont":n}lt(t){const e=[[]];for(const[n,r]of Array.from(t).entries())"\n"!==r?e[e.length-1].push({character:r,inputIndex:n}):e.push([]);return e}ut(t,e){return"rtl"===e?[...t].reverse():t}ft(t){const e=t.map(({character:t,inputIndex:e})=>({figChar:this.getCharacter(t)??this.getCharacter(32),inputChar:t,inputIndex:e})),r=e.find(t=>void 0===t.figChar);if(r)throw new n("FIGfont is missing a required character for layout.",{character:r.inputChar,index:r.inputIndex});return e}ht(t,e,n){const r="number"==typeof n.maxCols&&Number.isFinite(n.maxCols)?Math.floor(n.maxCols):void 0,i=n.wrap??"none";return 0===t.length||!r||r<1||"none"===i?[t]:"char"===i?this.dt(t,e,r):this.gt(t,e,r)}gt(t,e,n){const r=this._t(t);if(!r.some(t=>!t.isWhitespace))return[t];const i=[];let s=[],o=[];for(const a of r){if(a.isWhitespace){s.length>0&&(o=a.characters);continue}const t=0===s.length?a.characters:s.concat(o,a.characters);s.length>0&&this.wt(t,e)>n?(i.push(s),s=a.characters.slice()):s=t,o=[]}return 0===s.length?[[]]:(i.push(s),i)}dt(t,e,n){const r=[];let i=[];for(const s of t){const t=i.concat(s);i.length>0&&this.wt(t,e)>n?(r.push(i),i=[s]):i=t}return 0===i.length?[[]]:(r.push(i),r)}wt(t,e){const n=this.ft(t);return this.rt.O(n.map(t=>t.figChar),n.map(({inputChar:t,inputIndex:e})=>({inputChar:t,inputIndex:e})),e,0).cols}_t(t){const e=[];for(const n of t){const t=/\s/u.test(n.character),r=e[e.length-1];r&&r.isWhitespace===t?r.characters.push(n):e.push({isWhitespace:t,characters:[n]})}return e}ct(t){return"ltr"===t||"rtl"===t?t:this.defaultPrintDirection}};function l(t){if(t)return{...t,lines:[...t.lines]}}var u=Symbol.for("textmode.figlet.state");function h(t){const e=t;return e[u]||(e[u]={activeFont:void 0,align:"left",baseline:"baseline"}),e[u]}var f=["loadFigFont","parseFigFont","figFont","figText","figTextWidth","figTextHeight","figTextBounds","figTextAlign","figTextBaseline"];function d(t,e){if(void 0!==t)return"function"==typeof t?t(e):t}function g(t,n,r){return r instanceof e.color.TextmodeColor||"string"==typeof r||"number"==typeof r?"charColor"===n?void t.charColor(r):void t.cellColor(r):4===r.length?"charColor"===n?void t.charColor(r[0],r[1],r[2],r[3]):void t.cellColor(r[0],r[1],r[2],r[3]):void("charColor"!==n?t.cellColor(r[0],r[1],r[2]):t.charColor(r[0],r[1],r[2]))}function p(t){const e=h(t).activeFont;if(!e)throw new n("No FIGlet font is active. Call figFont() first.");return e}function _(t,e){t.It?.(e)}function w(t,e,n){Object.defineProperty(t,e,{value:n,writable:!0,configurable:!0,enumerable:!1})}var m={name:"textmode.figlet.js",version:"1.0.3-beta.1",install(t,e){!function(t){w(t,"loadFigFont",async function(t){const e=await c.it(t);return _(this,e),e}),w(t,"parseFigFont",function(t,e){const n=c.st(t,e);return _(this,n),n}),w(t,"figFont",function(t){const e=h(this);if(void 0===t)return e.activeFont;e.activeFont=t}),w(t,"figText",function(t,e,n,r={}){const i=p(this),s=i.planText(t,r),o=h(this),a=e+(c=s.cols,"center"===(l=o.align)?-Math.floor(c/2):"right"===l?-(c-1):0);var c,l;const u=n+(f=s.rows,_=i.baseline,"top"===(w=o.baseline)?0:"center"===w?-Math.floor(f/2):"bottom"===w?-(f-1):-(_-1));var f,_,w;this.push(),this.translate(a,u,0);for(const h of s.cells){this.push(),this.translate(h.col,h.row,0);const t=d(r.charColor,h),e=d(r.cellColor,h);this.char(h.char),void 0!==t&&g(this,"charColor",t),void 0!==e&&g(this,"cellColor",e),this.point(),this.pop()}this.pop()}),w(t,"figTextWidth",function(t,e={}){return p(this).measureText(t,e).cols}),w(t,"figTextHeight",function(t,e={}){return p(this).measureText(t,e).rows}),w(t,"figTextBounds",function(t,e={}){return p(this).measureText(t,e)}),w(t,"figTextAlign",function(t){const e=h(this);if(void 0===t)return e.align;e.align=t}),w(t,"figTextBaseline",function(t){const e=h(this);if(void 0===t)return e.baseline;e.baseline=t})}(t)},uninstall(t,e){!function(t){for(const e of f)delete t[e];!function(t){delete t[u]}(t)}(t)}};if("undefined"!=typeof window){const t=window;t.FigletPlugin=m,t.TextmodeFigFont=c,t.FigFontParser=i,t.FigLayoutEngine=o,t.FigSmushRules=s,t.FIGFONT_REQUIRED_CODEPOINTS=r}t.FIGFONT_REQUIRED_CODEPOINTS=r,t.FigFontParser=i,t.FigLayoutEngine=o,t.FigSmushRules=s,t.FigletPlugin=m,t.TextmodeFigFont=c});
|
|
@@ -6,6 +6,10 @@ import type { FigTextAlign, FigTextBaseline, FigTextOptions } from '../figfont';
|
|
|
6
6
|
/**
|
|
7
7
|
* FIGlet methods added to the `textmode.js` `Textmodifier` API when
|
|
8
8
|
* {@link FigletPlugin} is installed.
|
|
9
|
+
*
|
|
10
|
+
* @category Textmodifier extensions
|
|
11
|
+
*
|
|
12
|
+
* @see {@link https://code.textmode.art/api/textmode.figlet.js/interfaces/TextmodifierFigletExtensions | TextmodifierFigletExtensions API reference}
|
|
9
13
|
*/
|
|
10
14
|
export interface TextmodifierFigletExtensions {
|
|
11
15
|
/**
|
|
@@ -16,6 +20,8 @@ export interface TextmodifierFigletExtensions {
|
|
|
16
20
|
*
|
|
17
21
|
* @example
|
|
18
22
|
* {@includeCode ../../examples/Textmodifier/loadFigFont/sketch.js}
|
|
23
|
+
*
|
|
24
|
+
* @see {@link https://code.textmode.art/api/textmode.figlet.js/interfaces/TextmodifierFigletExtensions/methods/loadFigFont | TextmodifierFigletExtensions.loadFigFont API reference}
|
|
19
25
|
*/
|
|
20
26
|
loadFigFont(source: string | URL): Promise<TextmodeFigFont>;
|
|
21
27
|
/**
|
|
@@ -27,6 +33,8 @@ export interface TextmodifierFigletExtensions {
|
|
|
27
33
|
*
|
|
28
34
|
* @example
|
|
29
35
|
* {@includeCode ../../examples/Textmodifier/parseFigFont/sketch.js}
|
|
36
|
+
*
|
|
37
|
+
* @see {@link https://code.textmode.art/api/textmode.figlet.js/interfaces/TextmodifierFigletExtensions/methods/parseFigFont | TextmodifierFigletExtensions.parseFigFont API reference}
|
|
30
38
|
*/
|
|
31
39
|
parseFigFont(name: string, data: string): TextmodeFigFont;
|
|
32
40
|
/**
|
|
@@ -36,12 +44,16 @@ export interface TextmodifierFigletExtensions {
|
|
|
36
44
|
*
|
|
37
45
|
* @example
|
|
38
46
|
* {@includeCode ../../examples/Textmodifier/figFont/sketch.js}
|
|
47
|
+
*
|
|
48
|
+
* @see {@link https://code.textmode.art/api/textmode.figlet.js/interfaces/TextmodifierFigletExtensions/methods/figFont | TextmodifierFigletExtensions.figFont API reference}
|
|
39
49
|
*/
|
|
40
50
|
figFont(): TextmodeFigFont | undefined;
|
|
41
51
|
/**
|
|
42
52
|
* Set the active FIGlet font used by `figText()`.
|
|
43
53
|
*
|
|
44
54
|
* @param font The FIGlet font to use for subsequent text rendering.
|
|
55
|
+
*
|
|
56
|
+
* @see {@link https://code.textmode.art/api/textmode.figlet.js/interfaces/TextmodifierFigletExtensions/methods/figFont | TextmodifierFigletExtensions.figFont API reference}
|
|
45
57
|
*/
|
|
46
58
|
figFont(font: TextmodeFigFont): void;
|
|
47
59
|
/**
|
|
@@ -54,6 +66,8 @@ export interface TextmodifierFigletExtensions {
|
|
|
54
66
|
*
|
|
55
67
|
* @example
|
|
56
68
|
* {@includeCode ../../examples/Textmodifier/figText/sketch.js}
|
|
69
|
+
*
|
|
70
|
+
* @see {@link https://code.textmode.art/api/textmode.figlet.js/interfaces/TextmodifierFigletExtensions/methods/figText | TextmodifierFigletExtensions.figText API reference}
|
|
57
71
|
*/
|
|
58
72
|
figText(text: string, col: number, row: number, options?: FigTextOptions): void;
|
|
59
73
|
/**
|
|
@@ -65,6 +79,8 @@ export interface TextmodifierFigletExtensions {
|
|
|
65
79
|
*
|
|
66
80
|
* @example
|
|
67
81
|
* {@includeCode ../../examples/Textmodifier/figTextWidth/sketch.js}
|
|
82
|
+
*
|
|
83
|
+
* @see {@link https://code.textmode.art/api/textmode.figlet.js/interfaces/TextmodifierFigletExtensions/methods/figTextWidth | TextmodifierFigletExtensions.figTextWidth API reference}
|
|
68
84
|
*/
|
|
69
85
|
figTextWidth(text: string, options?: FigTextOptions): number;
|
|
70
86
|
/**
|
|
@@ -76,6 +92,8 @@ export interface TextmodifierFigletExtensions {
|
|
|
76
92
|
*
|
|
77
93
|
* @example
|
|
78
94
|
* {@includeCode ../../examples/Textmodifier/figTextHeight/sketch.js}
|
|
95
|
+
*
|
|
96
|
+
* @see {@link https://code.textmode.art/api/textmode.figlet.js/interfaces/TextmodifierFigletExtensions/methods/figTextHeight | TextmodifierFigletExtensions.figTextHeight API reference}
|
|
79
97
|
*/
|
|
80
98
|
figTextHeight(text: string, options?: FigTextOptions): number;
|
|
81
99
|
/**
|
|
@@ -87,6 +105,8 @@ export interface TextmodifierFigletExtensions {
|
|
|
87
105
|
*
|
|
88
106
|
* @example
|
|
89
107
|
* {@includeCode ../../examples/Textmodifier/figTextBounds/sketch.js}
|
|
108
|
+
*
|
|
109
|
+
* @see {@link https://code.textmode.art/api/textmode.figlet.js/interfaces/TextmodifierFigletExtensions/methods/figTextBounds | TextmodifierFigletExtensions.figTextBounds API reference}
|
|
90
110
|
*/
|
|
91
111
|
figTextBounds(text: string, options?: FigTextOptions): {
|
|
92
112
|
cols: number;
|
|
@@ -99,12 +119,16 @@ export interface TextmodifierFigletExtensions {
|
|
|
99
119
|
*
|
|
100
120
|
* @example
|
|
101
121
|
* {@includeCode ../../examples/Textmodifier/figTextAlign/sketch.js}
|
|
122
|
+
*
|
|
123
|
+
* @see {@link https://code.textmode.art/api/textmode.figlet.js/interfaces/TextmodifierFigletExtensions/methods/figTextAlign | TextmodifierFigletExtensions.figTextAlign API reference}
|
|
102
124
|
*/
|
|
103
125
|
figTextAlign(): FigTextAlign;
|
|
104
126
|
/**
|
|
105
127
|
* Set the horizontal FIGlet text alignment.
|
|
106
128
|
*
|
|
107
129
|
* @param align Alignment mode for subsequent `figText()` calls.
|
|
130
|
+
*
|
|
131
|
+
* @see {@link https://code.textmode.art/api/textmode.figlet.js/interfaces/TextmodifierFigletExtensions/methods/figTextAlign | TextmodifierFigletExtensions.figTextAlign API reference}
|
|
108
132
|
*/
|
|
109
133
|
figTextAlign(align: FigTextAlign): void;
|
|
110
134
|
/**
|
|
@@ -114,12 +138,16 @@ export interface TextmodifierFigletExtensions {
|
|
|
114
138
|
*
|
|
115
139
|
* @example
|
|
116
140
|
* {@includeCode ../../examples/Textmodifier/figTextBaseline/sketch.js}
|
|
141
|
+
*
|
|
142
|
+
* @see {@link https://code.textmode.art/api/textmode.figlet.js/interfaces/TextmodifierFigletExtensions/methods/figTextBaseline | TextmodifierFigletExtensions.figTextBaseline API reference}
|
|
117
143
|
*/
|
|
118
144
|
figTextBaseline(): FigTextBaseline;
|
|
119
145
|
/**
|
|
120
146
|
* Set the vertical FIGlet text baseline mode.
|
|
121
147
|
*
|
|
122
148
|
* @param baseline Baseline mode for subsequent `figText()` calls.
|
|
149
|
+
*
|
|
150
|
+
* @see {@link https://code.textmode.art/api/textmode.figlet.js/interfaces/TextmodifierFigletExtensions/methods/figTextBaseline | TextmodifierFigletExtensions.figTextBaseline API reference}
|
|
123
151
|
*/
|
|
124
152
|
figTextBaseline(baseline: FigTextBaseline): void;
|
|
125
153
|
}
|
|
@@ -127,4 +155,3 @@ declare module 'textmode.js' {
|
|
|
127
155
|
interface Textmodifier extends TextmodifierFigletExtensions {
|
|
128
156
|
}
|
|
129
157
|
}
|
|
130
|
-
//# sourceMappingURL=textmode.d.ts.map
|
|
@@ -11,4 +11,3 @@ export declare function installTextmodifierFigletExtensions(textmodifier: Textmo
|
|
|
11
11
|
* @param textmodifier Target instance.
|
|
12
12
|
*/
|
|
13
13
|
export declare function uninstallTextmodifierFigletExtensions(textmodifier: Textmodifier): void;
|
|
14
|
-
//# sourceMappingURL=textmodifier.d.ts.map
|