-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
180 lines (140 loc) · 8.1 KB
/
script.js
File metadata and controls
180 lines (140 loc) · 8.1 KB
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
require.config({ paths: { 'vs': 'https://apicenter.pages.dev/libraries/andorra/min/vs' } });
require([ 'vs/editor/editor.main', 'vs/language/typescript/andorra.contribution' ], function () {
var editor = andorra.editor.create(document.getElementById('editor'), {
autoClosingBrackets: 'always',
autoClosingComments: 'always',
autoClosingQuotes: 'always',
automaticLayout: true,
autoSurround: 'brackets',
codeActionsOn: { 'editor': 'always' },
codeActionsOnSave: { "source.fixAll": true, "source.organizeImports": true },
colorDecorators: true,
colorDecoratorsActivatedOn: "hover",
comments: { insertSpace: true },
contextmenu: true,
copyWithSyntaxHighlighting: true,
cursorBlinking: "blink", // "blink" | "smooth" | "phase" | "expand" | "solid"
cursorSmoothCaretAnimation: "on",
cursorStyle: 'line', // "line" | "block" | "underline" | "line-thin" | "block-outline" | "underline-thin"
cursorSurroundingLinesStyle: 'default',
defaultColorDecorators: "always",
definitionLinkOpensInPeek: true,
dragAndDrop: true,
dropIntoEditor: { enabled: true, showDropSelector: true },
editContext: true,
experimentalWhitespaceRendering: 'font',
find: { cursorMoveOnType: true, findOnType: true, },
foldingStrategy: 'indentation',
fontFamily: `Laurentia Mono, Consolium, 'Courier New', monospace`,
fontLigatures: "'ss19' 1",
fontSize: 16,
formatOnPaste: true,
formatOnType: true,
gotoLocation: { multiple: "peek" },
guides: { },
hover: { enabled: true },
language: 'html',
lightbulb: { enabled: true },
lineNumbers: 'on',
links: true,
matchBrackets: 'always',
minimap: { enabled: true },
mouseWheelZoom: true,
multiCursorLimit: 1000,
multiCursorModifier: 'alt',
multiCursorPaste: 'full',
occurrencesHighlight: 'singleFile',
parameterHints: { cycle: true, enabled: true },
peekWidgetDefaultFocus: 'editor',
quickSuggestions: { other: true, comments: true, strings: true },
quickSuggestionsDelay: 0,
renderWhitespace: 'selection',
scrollBeyondLastLine: true,
showDeprecated: true,
showFoldingControls: 'hover',
snippetSuggestions: 'inline',
suggestOnTriggerCharacters: true,
suggestSelection: 'first',
tabCompletion: 'on',
tabFocusMode: true,
theme: 'vs-dark',
unusualLineTerminators: 'prompt',
value: ``,
wordBreak: 'normal',
wordWrap: 'off',
wrappingStrategy: 'advanced',
});
// Ensure any custom fonts load properly.
function ensureFontsLoaded(callback) { document.fonts.ready.then(() => { andorra.editor.remeasureFonts(); callback(); }); }
ensureFontsLoaded(() => { console.log("WebHTML UI Manager: Fonts applied successfully!"); });
editor.onDidChangeModelContent(() => { const html = editor.getValue(); });
const PREVIEW_TITLE = 'Preview - Aurorasoft WebHTML';
const PREVIEW_FAVICON = 'https://webhtml.pages.dev/cdn/branding/images/favicon/favicon.svg?v1';
// Close any orphaned preview popups on load
try { if (window.opener === null && window.name === 'LivePreviewPopup') { window.close(); } } catch (e) {}
let previewPopupWindow = null;
let popupPreviewActive = false;
function togglePreviewPopup() {
const button = document.getElementById('previewPopup');
if (popupPreviewActive) { if (previewPopupWindow && !previewPopupWindow.closed) { previewPopupWindow.close(); } popupPreviewActive = false; previewPopupWindow = null; button.textContent = 'Run'; updatePreview(); return; }
previewPopupWindow = window.open(
'',
'LivePreviewPopup',
'width=900,height=600,resizable=yes,scrollbars=yes,popups=yes'
);
if (!previewPopupWindow) { alert('Popup blocked! Please allow popups.'); return; }
previewPopupWindow.document.open();
previewPopupWindow.document.write(`
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>${PREVIEW_TITLE}</title>
<link rel="icon" href="${PREVIEW_FAVICON}">
</head>
<body>
${editor.getValue()}
</body>
</html>
`);
previewPopupWindow.document.close();
popupPreviewActive = true;
button.textContent = 'Stop';
const popupCloseInterval = setInterval(() => { if (!previewPopupWindow || previewPopupWindow.closed) { clearInterval(popupCloseInterval); if (popupPreviewActive) { togglePreviewPopup(); } } }, 500);
}
function closePreviewPopupSafely() { if (previewPopupWindow && !previewPopupWindow.closed) { previewPopupWindow.close(); } }
updatePreview();
function openFile() { var input = document.createElement('input'); input.type = 'file'; input.accept = 'text/html'; input.onchange = function(event) { var file = event.target.files[0]; var reader = new FileReader(); reader.onload = function() { editor.setValue(reader.result); document.title = file.name + ' - Aurorasoft WebHTML'; updatePreview(); }; reader.readAsText(file); }; input.click(); }
function saveFile() { var content = editor.getValue(); var blob = new Blob([content], { type: 'text/html' }); var url = URL.createObjectURL(blob); var a = document.createElement('a'); a.href = url; var currentDate = new Date().toISOString().slice(0, 19).replace(/[-T:/]/g, ''); var fileName = 'WebHTML_' + currentDate + '.html'; a.download = fileName; document.title = fileName + ' - Aurorasoft WebHTML'; document.body.appendChild(a); a.click(); window.URL.revokeObjectURL(url); document.body.removeChild(a); isModified = false; }
document.getElementById('openButton').addEventListener('click', openFile);
document.getElementById('saveButton').addEventListener('click', saveFile);
window.addEventListener('beforeunload', closePreviewPopupSafely);
window.addEventListener('unload', closePreviewPopupSafely);
var isModified = false;
editor.onDidChangeModelContent(function() { isModified = true; var fileName = document.title; if (!fileName.endsWith('*')) { fileName += "*"; } document.title = fileName; updatePreview(); });
function updatePreview() {
if (previewPopupWindow && !previewPopupWindow.closed) {
previewPopupWindow.document.open();
previewPopupWindow.document.write(`
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>${PREVIEW_TITLE}</title>
<link rel="icon" type="image/png" href="${PREVIEW_FAVICON}">
</head>
<body>
${editor.getValue()}
</body>
</html>
`);
previewPopupWindow.document.close();
}
}
window.addEventListener('beforeunload', function(e) { if (isModified) { var confirmationMessage = 'You have unsaved changes. Are you sure you want to leave?'; e.returnValue = confirmationMessage; return confirmationMessage; } });
document
.getElementById('previewPopup')
.addEventListener('click', togglePreviewPopup);
window.addEventListener('keydown', function(event) { if (event.ctrlKey && event.key === 's') { event.preventDefault(); saveFile(); } else if (event.ctrlKey && event.key === 'o') { event.preventDefault(); openFile(); } else if (event.altKey && event.key === 'm') { event.preventDefault(); var minimapEnabled = editor.getOption(andorra.editor.EditorOption.minimap).enabled; editor.updateOptions({ minimap: { enabled: !minimapEnabled } }); } else if (event.altKey && event.key === 'z') { event.preventDefault(); var wordWrapEnabled = editor.getOption(andorra.editor.EditorOption.wordWrap) === 'on'; editor.updateOptions({ wordWrap: wordWrapEnabled ? 'off' : 'on' }); } else if (event.key === 'F5') { event.preventDefault(); togglePreviewPopup(); } });
document.getElementById('help').addEventListener('click', function() { window.open("https://aurorasoft.pages.dev/help/webhtml/") });
});