-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-test.js
executable file
·280 lines (276 loc) · 7.17 KB
/
create-test.js
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#!/usr/bin/env node
// create-test.js
// Generates a styled Base437 demo page with interactive elements
import { createEncoder, CoreMapping } from './base437.js';
import fs from 'fs';
const imagePath = process.argv[2];
let base437Url = '';
if (imagePath) {
const imageBuffer = fs.readFileSync(imagePath);
const htmlSafeMapping = CoreMapping.tr('"', 'U+201C').validate();
const htmlEncoder = createEncoder(htmlSafeMapping);
const base437Data = htmlEncoder.encode(new Uint8Array(imageBuffer));
base437Url = `data:image/png;base437,${base437Data}`;
}
// HTML content with inline CSS and structure
const htmlContent = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Base437 Interactive Demo</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 1200px;
margin: 0 auto;
padding: 20px;
background-color: #f0f0f0;
}
h1 {
color: #333;
text-align: center;
}
.container {
display: flex;
flex-wrap: wrap;
gap: 20px;
}
.section {
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
flex: 1;
min-width: 300px;
}
.mapping-section {
overflow-x: auto; /* Enable horizontal scrolling */
}
.mapping-section h2 {
position: sticky;
left: 0;
background: white; /* Ensure background matches section */
z-index: 1; /* Keep header above table */
margin: 0 0 10px 0;
padding: 0;
}
.mapping-table {
display: grid;
grid-template-columns: repeat(16, 1fr);
gap: 2px;
margin: 10px 0;
font-size: 12px;
min-width: 600px; /* Ensure table doesn't shrink too much */
}
.mapping-cell {
border: 1px solid #ddd;
padding: 5px;
text-align: center;
cursor: pointer;
background: #fff;
}
.mapping-cell:hover {
background: #f5f5f5;
}
textarea, input[type="text"] {
width: 100%;
padding: 8px;
margin: 5px 0;
box-sizing: border-box;
font-family: monospace;
}
button {
padding: 8px 16px;
margin: 5px 0;
background: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background: #0056b3;
}
select {
padding: 8px;
margin: 5px 0;
}
#downloadLink {
display: none;
margin-top: 10px;
}
img {
max-width: 100%;
height: auto;
margin-top: 10px;
}
dialog {
margin: 0;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border: 2px solid #ddd;
border-radius: 8px;
padding: 20px;
background: #fff;
font-family: Arial, sans-serif;
max-width: 400px;
box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}
dialog h3 {
margin: 0 0 15px;
color: #333;
font-size: 18px;
text-align: center;
}
dialog .metadata-table {
width: 100%;
border-collapse: collapse;
font-size: 12px;
margin-bottom: 15px;
}
dialog .metadata-table th,
dialog .metadata-table td {
border: 1px solid #ddd;
padding: 5px;
text-align: center;
}
dialog .metadata-table th {
background: #f5f5f5;
font-weight: bold;
color: #333;
}
dialog .metadata-table td {
color: #555;
}
dialog .metadata-table .char-display {
font-size: 14px;
font-weight: bold;
}
dialog .metadata-table .char-display.og {
color: #28a745;
}
dialog .metadata-table .char-display.current {
color: #007bff;
}
dialog .metadata-table .char-display span {
font-weight: normal;
color: #666;
font-size: 10px;
display: block;
}
dialog .input-section {
margin-bottom: 15px;
}
dialog label {
display: block;
margin-bottom: 5px;
font-weight: bold;
color: #333;
}
dialog input {
width: 100%;
padding: 5px;
font-family: monospace;
border: 1px solid #ddd;
border-radius: 4px;
box-sizing: border-box;
}
dialog .live-preview {
margin-top: 5px;
font-size: 14px;
color: #555;
}
dialog .live-preview span {
font-size: 16px;
font-weight: bold;
color: #ff6f61;
}
dialog .dialog-buttons {
text-align: right;
}
dialog button {
padding: 8px 16px;
margin-left: 10px;
background: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
dialog button:hover {
background: #0056b3;
}
dialog button.cancel {
background: #dc3545;
}
dialog button.cancel:hover {
background: #c82333;
}
</style>
</head>
<body>
<h1>Base437 Interactive Demo</h1>
<div class="container">
<div class="section mapping-section">
<h2>Mapping Table (Edit to Customize)</h2>
<div id="mappingTable" class="mapping-table"></div>
</div>
<div class="section">
<h2>Encode/Decode</h2>
<label><input type="radio" name="inputType" value="text" checked> Text</label>
<label><input type="radio" name="inputType" value="file"> File</label>
<textarea id="inputText" rows="4" placeholder="Enter text to encode..."></textarea>
<input type="file" id="inputFile" style="display: none;">
<button id="encodeBtn">Encode to Base437</button>
<textarea id="outputText" rows="4" placeholder="Base437 output will appear here..."></textarea>
<button id="decodeBtn">Decode from Base437</button>
<select id="outputType">
<option value="string">String</option>
<option value="file">File</option>
</select>
<a id="downloadLink" download="decoded_output">Download Decoded File</a>
</div>
${base437Url ? `
<div class="section">
<h2>Demo Image (Base437 Encoded)</h2>
<p>This image is loaded from a Base437 data URL and converted to Base64, using an HTML attribute safe variant of the CoreMapping.</p>
<img id="demoImage" src="${base437Url}" alt="Demo Image" width="200">
</div>` : ''}
</div>
<dialog id="editMappingDialog">
<h3>Edit Mapping</h3>
<table class="metadata-table">
<thead>
<tr>
<th>Binary</th>
<th>Original</th>
<th>Current</th>
</tr>
</thead>
<tbody>
<tr>
<td id="byteInfo"></td>
<td id="originalMapping"></td>
<td id="currentChar"></td>
</tr>
</tbody>
</table>
<div class="input-section">
<label for="newUnicode">New Unicode Value:</label>
<input type="text" id="newUnicode" placeholder="e.g., U+2060">
<div class="live-preview" id="livePreview">Live Preview: <span>-</span></div>
</div>
<div class="dialog-buttons">
<button class="cancel" onclick="document.getElementById('editMappingDialog').close()">Cancel</button>
<button id="saveMappingBtn">Save</button>
</div>
</dialog>
<script type="module" src="demo.js"></script>
</body>
</html>
`.trim();
// Write the index.html file
fs.writeFileSync('index.html', htmlContent);
console.log('Created index.html with Base437 interactive demo');