This repository was archived by the owner on Sep 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Expand file tree
/
Copy pathLiveDevelopment.js
More file actions
710 lines (622 loc) · 25.7 KB
/
LiveDevelopment.js
File metadata and controls
710 lines (622 loc) · 25.7 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
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
/*
* Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, forin: true, maxerr: 50, regexp: true */
/*global define, $, brackets, window */
/**
* LiveDevelopment manages the Inspector, all Agents, and the active LiveDocument
*
* # STARTING
*
* To start a session call `open`. This will read the currentDocument from brackets,
* launch the LiveBrowser (currently Chrome) with the remote debugger port open,
* establish the Inspector connection to the remote debugger, and finally load all
* agents.
*
* # STOPPING
*
* To stop a session call `close`. This will close the active browser window,
* disconnect the Inspector, unload all agents, and clean up.
*
* # STATUS
*
* Status updates are dispatched as `statusChange` jQuery events. The status
* codes are:
*
* -1: Error
* 0: Inactive
* 1: Connecting to the remote debugger
* 2: Loading agents
* 3: Active
* 4: Out of sync
*/
define(function LiveDevelopment(require, exports, module) {
"use strict";
require("utils/Global");
// Status Codes
var STATUS_ERROR = exports.STATUS_ERROR = -1;
var STATUS_INACTIVE = exports.STATUS_INACTIVE = 0;
var STATUS_CONNECTING = exports.STATUS_CONNECTING = 1;
var STATUS_LOADING_AGENTS = exports.STATUS_LOADING_AGENTS = 2;
var STATUS_ACTIVE = exports.STATUS_ACTIVE = 3;
var STATUS_OUT_OF_SYNC = exports.STATUS_OUT_OF_SYNC = 4;
var Dialogs = require("widgets/Dialogs"),
DocumentManager = require("document/DocumentManager"),
EditorManager = require("editor/EditorManager"),
FileUtils = require("file/FileUtils"),
NativeFileError = require("file/NativeFileError"),
NativeApp = require("utils/NativeApp"),
PreferencesDialogs = require("preferences/PreferencesDialogs"),
ProjectManager = require("project/ProjectManager"),
Strings = require("strings"),
StringUtils = require("utils/StringUtils");
// Inspector
var Inspector = require("LiveDevelopment/Inspector/Inspector");
// Documents
var CSSDocument = require("LiveDevelopment/Documents/CSSDocument"),
HTMLDocument = require("LiveDevelopment/Documents/HTMLDocument"),
JSDocument = require("LiveDevelopment/Documents/JSDocument");
// Agents
var agents = {
"console" : require("LiveDevelopment/Agents/ConsoleAgent"),
"remote" : require("LiveDevelopment/Agents/RemoteAgent"),
"network" : require("LiveDevelopment/Agents/NetworkAgent"),
"dom" : require("LiveDevelopment/Agents/DOMAgent"),
"css" : require("LiveDevelopment/Agents/CSSAgent"),
"script" : require("LiveDevelopment/Agents/ScriptAgent"),
"highlight" : require("LiveDevelopment/Agents/HighlightAgent"),
"goto" : require("LiveDevelopment/Agents/GotoAgent"),
"edit" : require("LiveDevelopment/Agents/EditAgent")
};
var launcherUrl = window.location.href.replace(/\/index.html.*/, "") + "/LiveDevelopment/launch.html";
// Some agents are still experimental, so we don't enable them all by default
// However, extensions can enable them by calling enableAgent().
// This object is used as a set (thus all properties have the value 'true').
// Property names should match property names in the 'agents' object.
var _enabledAgentNames = {
"console" : true,
"remote" : true,
"network" : true,
"dom" : true,
"css" : true,
"highlight" : true
};
// store the names (matching property names in the 'agent' object) of agents that we've loaded
var _loadedAgentNames = [];
var _liveDocument; // the document open for live editing.
var _relatedDocuments; // CSS and JS documents that are used by the live HTML document
function _isHtmlFileExt(ext) {
return (FileUtils.isStaticHtmlFileExt(ext) ||
(ProjectManager.getBaseUrl() && FileUtils.isServerHtmlFileExt(ext)));
}
/** Convert a URL to a local full file path */
function _urlToPath(url) {
var path,
baseUrl = ProjectManager.getBaseUrl();
if (baseUrl !== "" && url.indexOf(baseUrl) === 0) {
// Use base url to translate to local file path.
// Need to use encoded project path because it's decoded below.
path = url.replace(baseUrl, encodeURI(ProjectManager.getProjectRoot().fullPath));
} else if (url.indexOf("file://") === 0) {
// Convert a file URL to local file path
path = url.slice(7);
if (path && brackets.platform === "win" && path.charAt(0) === "/") {
path = path.slice(1);
}
}
return decodeURI(path);
}
/** Convert a local full file path to a URL */
function _pathToUrl(path) {
var url,
baseUrl = ProjectManager.getBaseUrl();
// See if base url has been specified and path is within project
if (baseUrl !== "" && ProjectManager.isWithinProject(path)) {
// Map to server url. Base url is already encoded, so don't encode again.
var encodedDocPath = encodeURI(path);
var encodedProjectPath = encodeURI(ProjectManager.getProjectRoot().fullPath);
url = encodedDocPath.replace(encodedProjectPath, baseUrl);
} else {
var prefix = "file://";
if (brackets.platform === "win") {
// The path on Windows starts with a drive letter (e.g. "C:").
// In order to make it a valid file: URL we need to add an
// additional slash to the prefix.
prefix += "/";
}
url = encodeURI(prefix + path);
}
return url;
}
/** Augments the given Brackets document with information that's useful for live development. */
function _setDocInfo(doc) {
var parentUrl,
rootUrl,
matches;
// FUTURE: some of these things should just be moved into core Document; others should
// be in a LiveDevelopment-specific object attached to the doc.
matches = /^(.*\/)(.+\.([^.]+))$/.exec(doc.file.fullPath);
if (!matches) {
return;
}
doc.extension = matches[3];
parentUrl = _pathToUrl(matches[1]);
doc.url = parentUrl + encodeURI(matches[2]);
// the root represents the document that should be displayed in the browser
// for live development (the file for HTML files, index.html for others)
// TODO: Issue #2033 Improve how default page is determined
rootUrl = (_isHtmlFileExt(matches[3]) ? doc.url : parentUrl + "index.html");
doc.root = { url: rootUrl };
}
/** Get the current document from the document manager
* _adds extension, url and root to the document
*/
function _getCurrentDocument() {
var doc = DocumentManager.getCurrentDocument();
if (doc) {
_setDocInfo(doc);
}
return doc;
}
/** Determine which document class should be used for a given document
* @param {Document} document
*/
function _classForDocument(doc) {
switch (doc.extension) {
case "css":
return CSSDocument;
case "js":
return exports.config.experimental ? JSDocument : null;
}
if (exports.config.experimental && _isHtmlFileExt(doc.extension)) {
return HTMLDocument;
}
return null;
}
function getLiveDocForPath(path) {
var docsToSearch = [];
if (_relatedDocuments) {
docsToSearch = docsToSearch.concat(_relatedDocuments);
}
if (_liveDocument) {
docsToSearch = docsToSearch.concat(_liveDocument);
}
var foundDoc;
docsToSearch.some(function matchesPath(ele) {
if (ele.doc.file.fullPath === path) {
foundDoc = ele;
return true;
}
return false;
});
return foundDoc;
}
function getLiveDocForEditor(editor) {
if (!editor) {
return null;
}
return getLiveDocForPath(editor.document.file.fullPath);
}
/**
* Removes the given CSS/JSDocument from _relatedDocuments. Signals that the
* given file is no longer associated with the HTML document that is live (e.g.
* if the related file has been deleted on disk).
*/
function _handleRelatedDocumentDeleted(event, liveDoc) {
var index = _relatedDocuments.indexOf(liveDoc);
if (index !== -1) {
$(liveDoc).on("deleted", _handleRelatedDocumentDeleted);
_relatedDocuments.splice(index, 1);
}
}
/** Close a live document */
function _closeDocument() {
if (_liveDocument) {
_liveDocument.close();
_liveDocument = undefined;
}
if (_relatedDocuments) {
_relatedDocuments.forEach(function (liveDoc) {
liveDoc.close();
$(liveDoc).off("deleted", _handleRelatedDocumentDeleted);
});
_relatedDocuments = undefined;
}
}
/** Create a live version of a Brackets document */
function _createDocument(doc, editor) {
var DocClass = _classForDocument(doc);
if (DocClass) {
return new DocClass(doc, editor);
} else {
return null;
}
}
/** Open a live document
* @param {Document} source document to open
*/
function _openDocument(doc, editor) {
_closeDocument();
_liveDocument = _createDocument(doc, editor);
// Gather related CSS documents.
// FUTURE: Gather related JS documents as well.
_relatedDocuments = [];
agents.css.getStylesheetURLs().forEach(function (url) {
// FUTURE: when we get truly async file handling, we might need to prevent other
// stuff from happening while we wait to add these listeners
DocumentManager.getDocumentForPath(_urlToPath(url))
.done(function (doc) {
if (!_liveDocument || (doc !== _liveDocument.doc)) {
_setDocInfo(doc);
var liveDoc = _createDocument(doc);
if (liveDoc) {
_relatedDocuments.push(liveDoc);
$(liveDoc).on("deleted", _handleRelatedDocumentDeleted);
}
}
});
});
}
/** Unload the agents */
function unloadAgents() {
_loadedAgentNames.forEach(function (name) {
agents[name].unload();
});
_loadedAgentNames = [];
}
/** Load the agents */
function loadAgents() {
var name, promises = [];
var agentsToLoad;
if (exports.config.experimental) {
// load all agents
agentsToLoad = agents;
} else {
// load only enabled agents
agentsToLoad = _enabledAgentNames;
}
for (name in agentsToLoad) {
if (agentsToLoad.hasOwnProperty(name) && agents[name] && agents[name].load) {
promises.push(agents[name].load());
_loadedAgentNames.push(name);
}
}
return promises;
}
/** Enable an agent. Takes effect next time a connection is made. Does not affect
* current live development sessions.
*
* @param {string} name of agent to enable
*/
function enableAgent(name) {
if (agents.hasOwnProperty(name) && !_enabledAgentNames.hasOwnProperty(name)) {
_enabledAgentNames[name] = true;
}
}
/** Disable an agent. Takes effect next time a connection is made. Does not affect
* current live development sessions.
*
* @param {string} name of agent to disable
*/
function disableAgent(name) {
if (_enabledAgentNames.hasOwnProperty(name)) {
delete _enabledAgentNames[name];
}
}
/** Update the status
* @param {integer} new status
*/
function _setStatus(status) {
exports.status = status;
$(exports).triggerHandler("statusChange", status);
}
/** Triggered by Inspector.error */
function _onError(event, error) {
var message;
// Sometimes error.message is undefined
if (!error.message) {
console.warn("Expected a non-empty string in error.message, got this instead:", error.message);
message = JSON.stringify(error);
} else {
message = error.message;
}
// Remove "Uncaught" from the beginning to avoid the inspector popping up
if (message && message.substr(0, 8) === "Uncaught") {
message = message.substr(9);
}
// Additional information, like exactly which parameter could not be processed.
var data = error.data;
if (Array.isArray(data)) {
message += "\n" + data.join("\n");
}
// Show the message, but include the error object for further information (e.g. error code)
console.error(message, error);
_setStatus(STATUS_ERROR);
}
/** Run when all agents are loaded */
function _onLoad() {
var doc = _getCurrentDocument();
if (!doc) {
return;
}
var editor = EditorManager.getCurrentFullEditor(),
status = STATUS_ACTIVE;
_openDocument(doc, editor);
if (doc.isDirty && _classForDocument(doc) !== CSSDocument) {
status = STATUS_OUT_OF_SYNC;
}
_setStatus(status);
}
/** Triggered by Inspector.detached */
function _onDetached(event, res) {
// res.reason, e.g. "replaced_with_devtools", "target_closed", "canceled_by_user"
// Sample list taken from https://chromiumcodereview.appspot.com/10947037/patch/12001/13004
// However, the link refers to the Chrome Extension API, it may not apply 100% to the Inspector API
}
/** Triggered by Inspector.connect */
function _onConnect(event) {
$(Inspector.Inspector).on("detached", _onDetached);
// Load agents
_setStatus(STATUS_LOADING_AGENTS);
var promises = loadAgents();
$.when.apply(undefined, promises).done(_onLoad).fail(_onError);
// Load the right document (some agents are waiting for the page's load event)
var doc = _getCurrentDocument();
if (doc) {
Inspector.Page.navigate(doc.root.url);
} else {
Inspector.Page.reload();
}
}
/** Triggered by Inspector.disconnect */
function _onDisconnect(event) {
$(Inspector.Inspector).off("detached", _onDetached);
unloadAgents();
_closeDocument();
_setStatus(STATUS_INACTIVE);
}
function _onReconnect() {
unloadAgents();
var promises = loadAgents();
_setStatus(STATUS_LOADING_AGENTS);
$.when.apply(undefined, promises).done(_onLoad).fail(_onError);
}
/** Open the Connection and go live */
function open() {
var result = new $.Deferred(),
promise = result.promise();
var doc = _getCurrentDocument();
var browserStarted = false;
var retryCount = 0;
function showWrongDocError() {
Dialogs.showModalDialog(
Dialogs.DIALOG_ID_ERROR,
Strings.LIVE_DEVELOPMENT_ERROR_TITLE,
Strings.LIVE_DEV_NEED_HTML_MESSAGE
);
result.reject();
}
function showNeedBaseUrlError() {
PreferencesDialogs.showProjectPreferencesDialog("", Strings.LIVE_DEV_NEED_BASEURL_MESSAGE)
.done(function (id) {
if (id === Dialogs.DIALOG_BTN_OK && ProjectManager.getBaseUrl()) {
// If base url is specifed, then re-invoke open() to continue
open();
result.resolve();
} else {
result.reject();
}
})
.fail(function () {
result.reject();
});
}
if (!doc || !doc.root) {
showWrongDocError();
} else {
if (!exports.config.experimental) {
if (FileUtils.isServerHtmlFileExt(doc.extension)) {
if (!ProjectManager.getBaseUrl()) {
showNeedBaseUrlError();
return promise;
}
} else if (!FileUtils.isStaticHtmlFileExt(doc.extension)) {
showWrongDocError();
return promise;
}
}
var url = doc.root.url;
_setStatus(STATUS_CONNECTING);
Inspector.connectToURL(url).done(result.resolve).fail(function onConnectFail(err) {
if (err === "CANCEL") {
result.reject(err);
return;
}
if (retryCount > 6) {
_setStatus(STATUS_ERROR);
Dialogs.showModalDialog(
Dialogs.DIALOG_ID_LIVE_DEVELOPMENT,
Strings.LIVE_DEVELOPMENT_RELAUNCH_TITLE,
Strings.LIVE_DEVELOPMENT_ERROR_MESSAGE
).done(function (id) {
if (id === Dialogs.DIALOG_BTN_OK) {
// User has chosen to reload Chrome, quit the running instance
_setStatus(STATUS_INACTIVE);
NativeApp.closeLiveBrowser()
.done(function () {
browserStarted = false;
window.setTimeout(function () {
open().done(result.resolve).fail(result.reject);
});
})
.fail(function (err) {
// Report error?
_setStatus(STATUS_ERROR);
browserStarted = false;
result.reject("CLOSE_LIVE_BROWSER");
});
} else {
result.reject("CANCEL");
}
});
return;
}
retryCount++;
if (!browserStarted && exports.status !== STATUS_ERROR) {
url = launcherUrl + "?" + encodeURIComponent(url);
// If err === FileError.ERR_NOT_FOUND, it means a remote debugger connection
// is available, but the requested URL is not loaded in the browser. In that
// case we want to launch the live browser (to open the url in a new tab)
// without using the --remote-debugging-port flag. This works around issues
// on Windows where Chrome can't be opened more than once with the
// --remote-debugging-port flag set.
NativeApp.openLiveBrowser(
url,
err !== NativeFileError.ERR_NOT_FOUND
)
.done(function () {
browserStarted = true;
})
.fail(function (err) {
var message;
_setStatus(STATUS_ERROR);
if (err === NativeFileError.NOT_FOUND_ERR) {
message = Strings.ERROR_CANT_FIND_CHROME;
} else {
message = StringUtils.format(Strings.ERROR_LAUNCHING_BROWSER, err);
}
// Append a message to direct users to the troubleshooting page.
if (message) {
message += " " + StringUtils.format(Strings.LIVE_DEVELOPMENT_TROUBLESHOOTING, brackets.config.troubleshoot_url);
}
Dialogs.showModalDialog(
Dialogs.DIALOG_ID_ERROR,
Strings.ERROR_LAUNCHING_BROWSER_TITLE,
message
);
result.reject("OPEN_LIVE_BROWSER");
});
}
if (exports.status !== STATUS_ERROR) {
window.setTimeout(function retryConnect() {
Inspector.connectToURL(url).done(result.resolve).fail(onConnectFail);
}, 500);
}
});
}
return promise;
}
/** Close the Connection */
function close() {
if (Inspector.connected()) {
Inspector.Runtime.evaluate("window.open('', '_self').close();");
}
Inspector.disconnect();
_setStatus(STATUS_INACTIVE);
}
/** Enable highlighting */
function showHighlight() {
var doc = getLiveDocForEditor(EditorManager.getActiveEditor());
if (doc instanceof CSSDocument) {
doc.updateHighlight();
}
}
/** Hide any active highlighting */
function hideHighlight() {
if (Inspector.connected() && agents.highlight) {
agents.highlight.hide();
}
}
/** Redraw highlights **/
function redrawHighlight() {
if (Inspector.connected() && agents.highlight) {
agents.highlight.redraw();
}
}
/** Triggered by a document change from the DocumentManager */
function _onDocumentChange() {
var doc = _getCurrentDocument(),
status = STATUS_ACTIVE;
if (!doc) {
return;
}
if (Inspector.connected()) {
hideHighlight();
if (agents.network && agents.network.wasURLRequested(doc.url)) {
_closeDocument();
var editor = EditorManager.getCurrentFullEditor();
_openDocument(doc, editor);
} else {
if (exports.config.experimental || _isHtmlFileExt(doc.extension)) {
close();
window.setTimeout(open);
}
}
if (doc.isDirty && _classForDocument(doc) !== CSSDocument) {
status = STATUS_OUT_OF_SYNC;
}
_setStatus(status);
}
}
/** Triggered by a document saved from the DocumentManager */
function _onDocumentSaved(event, doc) {
if (doc && Inspector.connected() && _classForDocument(doc) !== CSSDocument &&
agents.network && agents.network.wasURLRequested(doc.url)) {
// Reload HTML page
Inspector.Page.reload();
// Reload unsaved changes
_onReconnect();
}
}
/** Triggered by a change in dirty flag from the DocumentManager */
function _onDirtyFlagChange(event, doc) {
if (doc && Inspector.connected() && _classForDocument(doc) !== CSSDocument &&
agents.network && agents.network.wasURLRequested(doc.url)) {
// Set status to out of sync if dirty. Otherwise, set it to active status.
_setStatus(doc.isDirty ? STATUS_OUT_OF_SYNC : STATUS_ACTIVE);
}
}
/** Initialize the LiveDevelopment Session */
function init(theConfig) {
exports.config = theConfig;
$(Inspector).on("connect", _onConnect)
.on("disconnect", _onDisconnect)
.on("error", _onError);
$(DocumentManager).on("currentDocumentChange", _onDocumentChange)
.on("documentSaved", _onDocumentSaved)
.on("dirtyFlagChange", _onDirtyFlagChange);
}
// For unit testing
exports._pathToUrl = _pathToUrl;
exports._urlToPath = _urlToPath;
// Export public functions
exports.agents = agents;
exports.open = open;
exports.close = close;
exports.enableAgent = enableAgent;
exports.disableAgent = disableAgent;
exports.getLiveDocForPath = getLiveDocForPath;
exports.showHighlight = showHighlight;
exports.hideHighlight = hideHighlight;
exports.redrawHighlight = redrawHighlight;
exports.init = init;
});