dwv 0.31.0-rc.0 → 0.31.0
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/dist/dwv.js +291 -397
- package/dist/dwv.min.js +2 -2
- package/package.json +1 -4
- package/locales/de/overlays.json +0 -59
- package/locales/de/translation.json +0 -245
- package/locales/en/overlays.json +0 -59
- package/locales/en/translation.json +0 -245
- package/locales/es/overlays.json +0 -59
- package/locales/es/translation.json +0 -245
- package/locales/fr/overlays.json +0 -59
- package/locales/fr/translation.json +0 -245
- package/locales/it/overlays.json +0 -59
- package/locales/it/translation.json +0 -245
- package/locales/jp/overlays.json +0 -59
- package/locales/jp/translation.json +0 -245
- package/locales/ro/overlays.json +0 -59
- package/locales/ro/translation.json +0 -245
- package/locales/ru/overlays.json +0 -59
- package/locales/ru/translation.json +0 -245
- package/locales/zh/overlays.json +0 -59
- package/locales/zh/translation.json +0 -245
package/dist/dwv.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
/*! dwv 0.31.0
|
|
1
|
+
/*! dwv 0.31.0 2023-03-07 18:27:54 */
|
|
2
2
|
// Inspired from umdjs
|
|
3
3
|
// See https://github.com/umdjs/umd/blob/master/templates/returnExports.js
|
|
4
4
|
(function (root, factory) {
|
|
5
5
|
if (typeof define === 'function' && define.amd) {
|
|
6
6
|
// AMD. Register as an anonymous module.
|
|
7
7
|
define([
|
|
8
|
-
'i18next',
|
|
9
|
-
'i18next-http-backend',
|
|
10
|
-
'i18next-browser-languagedetector',
|
|
11
8
|
'jszip',
|
|
12
9
|
'konva',
|
|
13
10
|
'magic-wand-tool'
|
|
@@ -19,9 +16,6 @@
|
|
|
19
16
|
|
|
20
17
|
// Konva: requires 'canvas'
|
|
21
18
|
module.exports = factory(
|
|
22
|
-
require('i18next'),
|
|
23
|
-
require('i18next-http-backend'),
|
|
24
|
-
require('i18next-browser-languagedetector'),
|
|
25
19
|
require('jszip'),
|
|
26
20
|
require('konva/cmj'),
|
|
27
21
|
require('magic-wand-tool')
|
|
@@ -29,18 +23,12 @@
|
|
|
29
23
|
} else {
|
|
30
24
|
// Browser globals (root is window)
|
|
31
25
|
root.dwv = factory(
|
|
32
|
-
root.i18next,
|
|
33
|
-
root.i18nextHttpBackend,
|
|
34
|
-
root.i18nextBrowserLanguageDetector,
|
|
35
26
|
root.JSZip,
|
|
36
27
|
root.Konva,
|
|
37
28
|
root.MagicWand
|
|
38
29
|
);
|
|
39
30
|
}
|
|
40
31
|
}(this, function (
|
|
41
|
-
i18next,
|
|
42
|
-
i18nextHttpBackend,
|
|
43
|
-
i18nextBrowserLanguageDetector,
|
|
44
32
|
JSZip,
|
|
45
33
|
Konva,
|
|
46
34
|
MagicWand) {
|
|
@@ -57,16 +45,6 @@
|
|
|
57
45
|
return typeof mod !== 'undefined' &&
|
|
58
46
|
typeof mod.default !== 'undefined';
|
|
59
47
|
}
|
|
60
|
-
// i18next (>v17) comes as a module, see #862
|
|
61
|
-
if (isEsmModule(i18next)) {
|
|
62
|
-
i18next = i18next.default;
|
|
63
|
-
}
|
|
64
|
-
if (isEsmModule(i18nextHttpBackend)) {
|
|
65
|
-
i18nextHttpBackend = i18nextHttpBackend.default;
|
|
66
|
-
}
|
|
67
|
-
if (isEsmModule(i18nextBrowserLanguageDetector)) {
|
|
68
|
-
i18nextBrowserLanguageDetector = i18nextBrowserLanguageDetector.default;
|
|
69
|
-
}
|
|
70
48
|
// Konva (>=v8) comes as a module, see #1044
|
|
71
49
|
if (isEsmModule(Konva)) {
|
|
72
50
|
Konva = Konva.default;
|
|
@@ -1369,10 +1347,11 @@ dwv.App = function () {
|
|
|
1369
1347
|
}
|
|
1370
1348
|
|
|
1371
1349
|
// optional draw layer
|
|
1350
|
+
var drawLayer;
|
|
1372
1351
|
if (toolboxController && toolboxController.hasTool('Draw')) {
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1352
|
+
drawLayer = layerGroup.addDrawLayer();
|
|
1353
|
+
drawLayer.initialise(size2D, spacing2D, dataIndex);
|
|
1354
|
+
drawLayer.setPlaneHelper(viewLayer.getViewController().getPlaneHelper());
|
|
1376
1355
|
}
|
|
1377
1356
|
|
|
1378
1357
|
// sync layers position
|
|
@@ -1399,11 +1378,17 @@ dwv.App = function () {
|
|
|
1399
1378
|
// flip offset Y for axial aquired data
|
|
1400
1379
|
if (dataViewConfig.orientation !== 'axial') {
|
|
1401
1380
|
viewLayer.addFlipOffsetY();
|
|
1381
|
+
if (typeof drawLayer !== 'undefined') {
|
|
1382
|
+
drawLayer.addFlipOffsetY();
|
|
1383
|
+
}
|
|
1402
1384
|
}
|
|
1403
1385
|
} else if (major === 0) {
|
|
1404
1386
|
// flip offset X for sagittal aquired data
|
|
1405
1387
|
if (dataViewConfig.orientation !== 'sagittal') {
|
|
1406
1388
|
viewLayer.addFlipOffsetX();
|
|
1389
|
+
if (typeof drawLayer !== 'undefined') {
|
|
1390
|
+
drawLayer.addFlipOffsetX();
|
|
1391
|
+
}
|
|
1407
1392
|
}
|
|
1408
1393
|
}
|
|
1409
1394
|
}
|
|
@@ -1417,6 +1402,9 @@ dwv.App = function () {
|
|
|
1417
1402
|
layerGroup.flipScaleZ();
|
|
1418
1403
|
} else {
|
|
1419
1404
|
viewLayer.setScale(layerGroup.getScale());
|
|
1405
|
+
if (typeof drawLayer !== 'undefined') {
|
|
1406
|
+
drawLayer.setScale(layerGroup.getScale());
|
|
1407
|
+
}
|
|
1420
1408
|
}
|
|
1421
1409
|
} else {
|
|
1422
1410
|
if (major === 0) {
|
|
@@ -1424,10 +1412,16 @@ dwv.App = function () {
|
|
|
1424
1412
|
layerGroup.flipScaleZ();
|
|
1425
1413
|
} else {
|
|
1426
1414
|
viewLayer.setScale(layerGroup.getScale());
|
|
1415
|
+
if (typeof drawLayer !== 'undefined') {
|
|
1416
|
+
drawLayer.setScale(layerGroup.getScale());
|
|
1417
|
+
}
|
|
1427
1418
|
}
|
|
1428
1419
|
}
|
|
1429
1420
|
} else {
|
|
1430
1421
|
viewLayer.setScale(layerGroup.getScale());
|
|
1422
|
+
if (typeof drawLayer !== 'undefined') {
|
|
1423
|
+
drawLayer.setScale(layerGroup.getScale());
|
|
1424
|
+
}
|
|
1431
1425
|
}
|
|
1432
1426
|
|
|
1433
1427
|
}
|
|
@@ -4755,7 +4749,7 @@ dwv.dicom = dwv.dicom || {};
|
|
|
4755
4749
|
* @returns {string} The version of the library.
|
|
4756
4750
|
*/
|
|
4757
4751
|
dwv.getVersion = function () {
|
|
4758
|
-
return '0.31.0
|
|
4752
|
+
return '0.31.0';
|
|
4759
4753
|
};
|
|
4760
4754
|
|
|
4761
4755
|
/**
|
|
@@ -12910,6 +12904,14 @@ dwv.gui.DrawLayer = function (containerDiv) {
|
|
|
12910
12904
|
*/
|
|
12911
12905
|
var zoomOffset = {x: 0, y: 0};
|
|
12912
12906
|
|
|
12907
|
+
/**
|
|
12908
|
+
* The flip offset.
|
|
12909
|
+
*
|
|
12910
|
+
* @private
|
|
12911
|
+
* @type {object}
|
|
12912
|
+
*/
|
|
12913
|
+
var flipOffset = {x: 0, y: 0};
|
|
12914
|
+
|
|
12913
12915
|
/**
|
|
12914
12916
|
* The draw controller.
|
|
12915
12917
|
*
|
|
@@ -13026,6 +13028,36 @@ dwv.gui.DrawLayer = function (containerDiv) {
|
|
|
13026
13028
|
konvaStage.opacity(Math.min(Math.max(alpha, 0), 1));
|
|
13027
13029
|
};
|
|
13028
13030
|
|
|
13031
|
+
/**
|
|
13032
|
+
* Add a flip offset along the layer X axis.
|
|
13033
|
+
*/
|
|
13034
|
+
this.addFlipOffsetX = function () {
|
|
13035
|
+
// flip scale is handled by layer group
|
|
13036
|
+
// flip offset
|
|
13037
|
+
var scale = konvaStage.scale();
|
|
13038
|
+
var size = konvaStage.size();
|
|
13039
|
+
flipOffset.x += size.width / scale.x;
|
|
13040
|
+
// apply
|
|
13041
|
+
var offset = konvaStage.offset();
|
|
13042
|
+
offset.x += flipOffset.x;
|
|
13043
|
+
konvaStage.offset(offset);
|
|
13044
|
+
};
|
|
13045
|
+
|
|
13046
|
+
/**
|
|
13047
|
+
* Add a flip offset along the layer Y axis.
|
|
13048
|
+
*/
|
|
13049
|
+
this.addFlipOffsetY = function () {
|
|
13050
|
+
// flip scale is handled by layer group
|
|
13051
|
+
// flip offset
|
|
13052
|
+
var scale = konvaStage.scale();
|
|
13053
|
+
var size = konvaStage.size();
|
|
13054
|
+
flipOffset.y += size.height / scale.y;
|
|
13055
|
+
// apply
|
|
13056
|
+
var offset = konvaStage.offset();
|
|
13057
|
+
offset.y += flipOffset.y;
|
|
13058
|
+
konvaStage.offset(offset);
|
|
13059
|
+
};
|
|
13060
|
+
|
|
13029
13061
|
/**
|
|
13030
13062
|
* Set the layer scale.
|
|
13031
13063
|
*
|
|
@@ -13093,8 +13125,10 @@ dwv.gui.DrawLayer = function (containerDiv) {
|
|
|
13093
13125
|
this.setOffset = function (newOffset) {
|
|
13094
13126
|
var planeNewOffset = planeHelper.getPlaneOffsetFromOffset3D(newOffset);
|
|
13095
13127
|
konvaStage.offset({
|
|
13096
|
-
x:
|
|
13097
|
-
|
|
13128
|
+
x: planeNewOffset.x +
|
|
13129
|
+
viewOffset.x + baseOffset.x + zoomOffset.x + flipOffset.x,
|
|
13130
|
+
y: planeNewOffset.y +
|
|
13131
|
+
viewOffset.y + baseOffset.y + zoomOffset.y + flipOffset.y
|
|
13098
13132
|
});
|
|
13099
13133
|
};
|
|
13100
13134
|
|
|
@@ -13221,8 +13255,8 @@ dwv.gui.DrawLayer = function (containerDiv) {
|
|
|
13221
13255
|
y: fitOffset.y / fitScale.y
|
|
13222
13256
|
};
|
|
13223
13257
|
konvaStage.offset({
|
|
13224
|
-
x: viewOffset.x + baseOffset.x + zoomOffset.x,
|
|
13225
|
-
y: viewOffset.y + baseOffset.y + zoomOffset.y
|
|
13258
|
+
x: viewOffset.x + baseOffset.x + zoomOffset.x + flipOffset.x,
|
|
13259
|
+
y: viewOffset.y + baseOffset.y + zoomOffset.y + flipOffset.y
|
|
13226
13260
|
});
|
|
13227
13261
|
};
|
|
13228
13262
|
|
|
@@ -30886,6 +30920,37 @@ dwv.tool.Draw = function (app) {
|
|
|
30886
30920
|
*/
|
|
30887
30921
|
var lastPoint = null;
|
|
30888
30922
|
|
|
30923
|
+
/**
|
|
30924
|
+
* Active shape, ie shape with mouse over.
|
|
30925
|
+
*
|
|
30926
|
+
* @private
|
|
30927
|
+
* @type {object}
|
|
30928
|
+
*/
|
|
30929
|
+
var activeShapeGroup;
|
|
30930
|
+
|
|
30931
|
+
/**
|
|
30932
|
+
* Original mouse cursor.
|
|
30933
|
+
*
|
|
30934
|
+
* @private
|
|
30935
|
+
* @type {string}
|
|
30936
|
+
*/
|
|
30937
|
+
var originalCursor;
|
|
30938
|
+
|
|
30939
|
+
/**
|
|
30940
|
+
* Mouse cursor.
|
|
30941
|
+
*
|
|
30942
|
+
* @private
|
|
30943
|
+
* @type {string}
|
|
30944
|
+
*/
|
|
30945
|
+
var mouseOverCursor = 'pointer';
|
|
30946
|
+
|
|
30947
|
+
/**
|
|
30948
|
+
* Scroll wheel handler.
|
|
30949
|
+
*
|
|
30950
|
+
* @type {dwv.tool.ScrollWheel}
|
|
30951
|
+
*/
|
|
30952
|
+
var scrollWhell = new dwv.tool.ScrollWheel(app);
|
|
30953
|
+
|
|
30889
30954
|
/**
|
|
30890
30955
|
* Shape editor.
|
|
30891
30956
|
*
|
|
@@ -31153,6 +31218,15 @@ dwv.tool.Draw = function (app) {
|
|
|
31153
31218
|
self.dblclick(event);
|
|
31154
31219
|
};
|
|
31155
31220
|
|
|
31221
|
+
/**
|
|
31222
|
+
* Handle mouse wheel event.
|
|
31223
|
+
*
|
|
31224
|
+
* @param {object} event The mouse wheel event.
|
|
31225
|
+
*/
|
|
31226
|
+
this.wheel = function (event) {
|
|
31227
|
+
scrollWhell.wheel(event);
|
|
31228
|
+
};
|
|
31229
|
+
|
|
31156
31230
|
/**
|
|
31157
31231
|
* Handle key down event.
|
|
31158
31232
|
*
|
|
@@ -31285,12 +31359,13 @@ dwv.tool.Draw = function (app) {
|
|
|
31285
31359
|
shapeEditor.disable();
|
|
31286
31360
|
shapeEditor.setShape(null);
|
|
31287
31361
|
shapeEditor.setViewController(null);
|
|
31288
|
-
document.body.style.cursor = 'default';
|
|
31289
31362
|
// get the current draw layer
|
|
31290
31363
|
var layerGroup = app.getActiveLayerGroup();
|
|
31291
31364
|
activateCurrentPositionShapes(flag, layerGroup);
|
|
31292
31365
|
// listen to app change to update the draw layer
|
|
31293
31366
|
if (flag) {
|
|
31367
|
+
// store cursor
|
|
31368
|
+
originalCursor = document.body.style.cursor;
|
|
31294
31369
|
// TODO: merge with drawController.activateDrawLayer?
|
|
31295
31370
|
app.addEventListener('positionchange', function () {
|
|
31296
31371
|
updateDrawLayer(layerGroup);
|
|
@@ -31298,6 +31373,11 @@ dwv.tool.Draw = function (app) {
|
|
|
31298
31373
|
// same for colour
|
|
31299
31374
|
this.setFeatures({lineColour: this.style.getLineColour()});
|
|
31300
31375
|
} else {
|
|
31376
|
+
// reset shape and cursor
|
|
31377
|
+
resetActiveShapeGroup();
|
|
31378
|
+
// reset local var
|
|
31379
|
+
originalCursor = undefined;
|
|
31380
|
+
// remove listeners
|
|
31301
31381
|
app.removeEventListener('positionchange', function () {
|
|
31302
31382
|
updateDrawLayer(layerGroup);
|
|
31303
31383
|
});
|
|
@@ -31384,6 +31464,24 @@ dwv.tool.Draw = function (app) {
|
|
|
31384
31464
|
};
|
|
31385
31465
|
}
|
|
31386
31466
|
|
|
31467
|
+
/**
|
|
31468
|
+
* Reset the active shape group and mouse cursor to their original state.
|
|
31469
|
+
*/
|
|
31470
|
+
function resetActiveShapeGroup() {
|
|
31471
|
+
if (typeof originalCursor !== 'undefined') {
|
|
31472
|
+
document.body.style.cursor = originalCursor;
|
|
31473
|
+
}
|
|
31474
|
+
if (typeof activeShapeGroup !== 'undefined') {
|
|
31475
|
+
activeShapeGroup.opacity(1);
|
|
31476
|
+
var colour = self.style.getLineColour();
|
|
31477
|
+
activeShapeGroup.getChildren(dwv.draw.canNodeChangeColour).forEach(
|
|
31478
|
+
function (ashape) {
|
|
31479
|
+
ashape.stroke(colour);
|
|
31480
|
+
}
|
|
31481
|
+
);
|
|
31482
|
+
}
|
|
31483
|
+
}
|
|
31484
|
+
|
|
31387
31485
|
/**
|
|
31388
31486
|
* Set shape group on properties.
|
|
31389
31487
|
*
|
|
@@ -31391,13 +31489,24 @@ dwv.tool.Draw = function (app) {
|
|
|
31391
31489
|
* @param {dwv.gui.LayerGroup} layerGroup The origin layer group.
|
|
31392
31490
|
*/
|
|
31393
31491
|
this.setShapeOn = function (shapeGroup, layerGroup) {
|
|
31394
|
-
// mouse over
|
|
31492
|
+
// adapt shape and cursor when mouse over
|
|
31493
|
+
var mouseOnShape = function () {
|
|
31494
|
+
document.body.style.cursor = mouseOverCursor;
|
|
31495
|
+
shapeGroup.opacity(0.75);
|
|
31496
|
+
};
|
|
31497
|
+
// mouse over event hanlding
|
|
31395
31498
|
shapeGroup.on('mouseover', function () {
|
|
31396
|
-
|
|
31499
|
+
// save local vars
|
|
31500
|
+
activeShapeGroup = shapeGroup;
|
|
31501
|
+
// adapt shape
|
|
31502
|
+
mouseOnShape();
|
|
31397
31503
|
});
|
|
31398
|
-
// mouse out
|
|
31504
|
+
// mouse out event hanlding
|
|
31399
31505
|
shapeGroup.on('mouseout', function () {
|
|
31400
|
-
|
|
31506
|
+
// reset shape
|
|
31507
|
+
resetActiveShapeGroup();
|
|
31508
|
+
// reset local vars
|
|
31509
|
+
activeShapeGroup = undefined;
|
|
31401
31510
|
});
|
|
31402
31511
|
|
|
31403
31512
|
var drawLayer = layerGroup.getActiveDrawLayer();
|
|
@@ -31487,9 +31596,14 @@ dwv.tool.Draw = function (app) {
|
|
|
31487
31596
|
});
|
|
31488
31597
|
// drag end event handling
|
|
31489
31598
|
shapeGroup.on('dragend.draw', function (event) {
|
|
31490
|
-
var pos = {x: this.x(), y: this.y()};
|
|
31491
31599
|
// remove trash
|
|
31492
31600
|
trash.remove();
|
|
31601
|
+
// activate(false) will also trigger a dragend.draw
|
|
31602
|
+
if (typeof event === 'undefined' ||
|
|
31603
|
+
typeof event.evt === 'undefined') {
|
|
31604
|
+
return;
|
|
31605
|
+
}
|
|
31606
|
+
var pos = {x: this.x(), y: this.y()};
|
|
31493
31607
|
// delete case
|
|
31494
31608
|
var offset = dwv.gui.getEventOffset(event.evt)[0];
|
|
31495
31609
|
var eventPos = getRealPosition(offset, layerGroup);
|
|
@@ -31510,7 +31624,7 @@ dwv.tool.Draw = function (app) {
|
|
|
31510
31624
|
ashape.stroke(colour);
|
|
31511
31625
|
});
|
|
31512
31626
|
// reset cursor
|
|
31513
|
-
document.body.style.cursor =
|
|
31627
|
+
document.body.style.cursor = originalCursor;
|
|
31514
31628
|
// delete command
|
|
31515
31629
|
var delcmd = new dwv.tool.DeleteGroupCommand(this,
|
|
31516
31630
|
shapeDisplayName, konvaLayer);
|
|
@@ -31625,6 +31739,9 @@ dwv.tool.Draw = function (app) {
|
|
|
31625
31739
|
}
|
|
31626
31740
|
this.shapeName = features.shapeName;
|
|
31627
31741
|
}
|
|
31742
|
+
if (typeof features.mouseOverCursor !== 'undefined') {
|
|
31743
|
+
mouseOverCursor = features.mouseOverCursor;
|
|
31744
|
+
}
|
|
31628
31745
|
};
|
|
31629
31746
|
|
|
31630
31747
|
/**
|
|
@@ -31696,24 +31813,6 @@ dwv.tool.Draw = function (app) {
|
|
|
31696
31813
|
|
|
31697
31814
|
}; // Draw class
|
|
31698
31815
|
|
|
31699
|
-
/**
|
|
31700
|
-
* Help for this tool.
|
|
31701
|
-
*
|
|
31702
|
-
* @returns {object} The help content.
|
|
31703
|
-
*/
|
|
31704
|
-
dwv.tool.Draw.prototype.getHelpKeys = function () {
|
|
31705
|
-
return {
|
|
31706
|
-
title: 'tool.Draw.name',
|
|
31707
|
-
brief: 'tool.Draw.brief',
|
|
31708
|
-
mouse: {
|
|
31709
|
-
mouse_drag: 'tool.Draw.mouse_drag'
|
|
31710
|
-
},
|
|
31711
|
-
touch: {
|
|
31712
|
-
touch_drag: 'tool.Draw.touch_drag'
|
|
31713
|
-
}
|
|
31714
|
-
};
|
|
31715
|
-
};
|
|
31716
|
-
|
|
31717
31816
|
/**
|
|
31718
31817
|
* Check if the shape is in the shape list.
|
|
31719
31818
|
*
|
|
@@ -32202,6 +32301,7 @@ var Konva = Konva || {};
|
|
|
32202
32301
|
* @returns {object} The default anchor shape.
|
|
32203
32302
|
*/
|
|
32204
32303
|
dwv.tool.draw.getDefaultAnchor = function (x, y, id, style) {
|
|
32304
|
+
var radius = style.applyZoomScale(3);
|
|
32205
32305
|
return new Konva.Ellipse({
|
|
32206
32306
|
x: x,
|
|
32207
32307
|
y: y,
|
|
@@ -32209,7 +32309,10 @@ dwv.tool.draw.getDefaultAnchor = function (x, y, id, style) {
|
|
|
32209
32309
|
fill: 'rgba(100,100,100,0.7',
|
|
32210
32310
|
strokeWidth: style.getStrokeWidth(),
|
|
32211
32311
|
strokeScaleEnabled: false,
|
|
32212
|
-
radius:
|
|
32312
|
+
radius: {
|
|
32313
|
+
x: Math.abs(radius.x),
|
|
32314
|
+
y: Math.abs(radius.y)
|
|
32315
|
+
},
|
|
32213
32316
|
name: 'anchor',
|
|
32214
32317
|
id: id,
|
|
32215
32318
|
dragOnTop: false,
|
|
@@ -33087,18 +33190,6 @@ dwv.tool.Filter = function (app) {
|
|
|
33087
33190
|
|
|
33088
33191
|
}; // class dwv.tool.Filter
|
|
33089
33192
|
|
|
33090
|
-
/**
|
|
33091
|
-
* Help for this tool.
|
|
33092
|
-
*
|
|
33093
|
-
* @returns {object} The help content.
|
|
33094
|
-
*/
|
|
33095
|
-
dwv.tool.Filter.prototype.getHelpKeys = function () {
|
|
33096
|
-
return {
|
|
33097
|
-
title: 'tool.Filter.name',
|
|
33098
|
-
brief: 'tool.Filter.brief'
|
|
33099
|
-
};
|
|
33100
|
-
};
|
|
33101
|
-
|
|
33102
33193
|
/**
|
|
33103
33194
|
* Get the selected filter.
|
|
33104
33195
|
*
|
|
@@ -34026,24 +34117,6 @@ dwv.tool.Floodfill = function (app) {
|
|
|
34026
34117
|
|
|
34027
34118
|
}; // Floodfill class
|
|
34028
34119
|
|
|
34029
|
-
/**
|
|
34030
|
-
* Help for this tool.
|
|
34031
|
-
*
|
|
34032
|
-
* @returns {object} The help content.
|
|
34033
|
-
*/
|
|
34034
|
-
dwv.tool.Floodfill.prototype.getHelpKeys = function () {
|
|
34035
|
-
return {
|
|
34036
|
-
title: 'tool.Floodfill.name',
|
|
34037
|
-
brief: 'tool.Floodfill.brief',
|
|
34038
|
-
mouse: {
|
|
34039
|
-
click: 'tool.Floodfill.click'
|
|
34040
|
-
},
|
|
34041
|
-
touch: {
|
|
34042
|
-
tap: 'tool.Floodfill.tap'
|
|
34043
|
-
}
|
|
34044
|
-
};
|
|
34045
|
-
};
|
|
34046
|
-
|
|
34047
34120
|
/**
|
|
34048
34121
|
* Set the tool live features: shape colour.
|
|
34049
34122
|
*
|
|
@@ -34367,6 +34440,24 @@ dwv.tool.Livewire = function (app) {
|
|
|
34367
34440
|
*/
|
|
34368
34441
|
var scissors = new dwv.math.Scissors();
|
|
34369
34442
|
|
|
34443
|
+
/**
|
|
34444
|
+
* Finish a livewire (roi) shape.
|
|
34445
|
+
*/
|
|
34446
|
+
function finishShape() {
|
|
34447
|
+
// fire creation event (was not propagated during draw)
|
|
34448
|
+
fireEvent({
|
|
34449
|
+
type: 'drawcreate',
|
|
34450
|
+
id: shapeGroup.id()
|
|
34451
|
+
});
|
|
34452
|
+
// listen
|
|
34453
|
+
command.onExecute = fireEvent;
|
|
34454
|
+
command.onUndo = fireEvent;
|
|
34455
|
+
// save command in undo stack
|
|
34456
|
+
app.addToUndoStack(command);
|
|
34457
|
+
// set flag
|
|
34458
|
+
self.started = false;
|
|
34459
|
+
}
|
|
34460
|
+
|
|
34370
34461
|
/**
|
|
34371
34462
|
* Handle mouse down event.
|
|
34372
34463
|
*
|
|
@@ -34403,17 +34494,8 @@ dwv.tool.Livewire = function (app) {
|
|
|
34403
34494
|
// final point: at 'tolerance' of the initial point
|
|
34404
34495
|
if ((Math.abs(index.get(0) - self.x0) < tolerance) &&
|
|
34405
34496
|
(Math.abs(index.get(1) - self.y0) < tolerance)) {
|
|
34406
|
-
//
|
|
34407
|
-
|
|
34408
|
-
// listen
|
|
34409
|
-
command.onExecute = fireEvent;
|
|
34410
|
-
command.onUndo = fireEvent;
|
|
34411
|
-
// debug
|
|
34412
|
-
dwv.logger.debug('[livewire] finialise path.');
|
|
34413
|
-
// save command in undo stack
|
|
34414
|
-
app.addToUndoStack(command);
|
|
34415
|
-
// set flag
|
|
34416
|
-
self.started = false;
|
|
34497
|
+
// finish
|
|
34498
|
+
finishShape();
|
|
34417
34499
|
} else {
|
|
34418
34500
|
// anchor point
|
|
34419
34501
|
path = currentPath;
|
|
@@ -34445,7 +34527,6 @@ dwv.tool.Livewire = function (app) {
|
|
|
34445
34527
|
// do the work
|
|
34446
34528
|
var results = 0;
|
|
34447
34529
|
var stop = false;
|
|
34448
|
-
dwv.logger.debug('[livewire] getting ready...');
|
|
34449
34530
|
while (!parentPoints[p.y][p.x] && !stop) {
|
|
34450
34531
|
results = scissors.doWork();
|
|
34451
34532
|
|
|
@@ -34460,7 +34541,6 @@ dwv.tool.Livewire = function (app) {
|
|
|
34460
34541
|
}
|
|
34461
34542
|
}
|
|
34462
34543
|
}
|
|
34463
|
-
dwv.logger.debug('[livewire] ready!');
|
|
34464
34544
|
|
|
34465
34545
|
// get the path
|
|
34466
34546
|
currentPath = new dwv.math.Path();
|
|
@@ -34528,11 +34608,7 @@ dwv.tool.Livewire = function (app) {
|
|
|
34528
34608
|
* @param {object} _event The double click event.
|
|
34529
34609
|
*/
|
|
34530
34610
|
this.dblclick = function (_event) {
|
|
34531
|
-
|
|
34532
|
-
// save command in undo stack
|
|
34533
|
-
app.addToUndoStack(command);
|
|
34534
|
-
// set flag
|
|
34535
|
-
self.started = false;
|
|
34611
|
+
finishShape();
|
|
34536
34612
|
};
|
|
34537
34613
|
|
|
34538
34614
|
/**
|
|
@@ -34648,18 +34724,6 @@ dwv.tool.Livewire = function (app) {
|
|
|
34648
34724
|
|
|
34649
34725
|
}; // Livewire class
|
|
34650
34726
|
|
|
34651
|
-
/**
|
|
34652
|
-
* Help for this tool.
|
|
34653
|
-
*
|
|
34654
|
-
* @returns {object} The help content.
|
|
34655
|
-
*/
|
|
34656
|
-
dwv.tool.Livewire.prototype.getHelpKeys = function () {
|
|
34657
|
-
return {
|
|
34658
|
-
title: 'tool.Livewire.name',
|
|
34659
|
-
brief: 'tool.Livewire.brief'
|
|
34660
|
-
};
|
|
34661
|
-
};
|
|
34662
|
-
|
|
34663
34727
|
/**
|
|
34664
34728
|
* Set the tool live features: shape colour.
|
|
34665
34729
|
*
|
|
@@ -34712,6 +34776,13 @@ dwv.tool.Opacity = function (app) {
|
|
|
34712
34776
|
*/
|
|
34713
34777
|
this.started = false;
|
|
34714
34778
|
|
|
34779
|
+
/**
|
|
34780
|
+
* Scroll wheel handler.
|
|
34781
|
+
*
|
|
34782
|
+
* @type {dwv.tool.ScrollWheel}
|
|
34783
|
+
*/
|
|
34784
|
+
var scrollWhell = new dwv.tool.ScrollWheel(app);
|
|
34785
|
+
|
|
34715
34786
|
/**
|
|
34716
34787
|
* Handle mouse down event.
|
|
34717
34788
|
*
|
|
@@ -34803,6 +34874,15 @@ dwv.tool.Opacity = function (app) {
|
|
|
34803
34874
|
self.mouseup(event);
|
|
34804
34875
|
};
|
|
34805
34876
|
|
|
34877
|
+
/**
|
|
34878
|
+
* Handle mouse wheel event.
|
|
34879
|
+
*
|
|
34880
|
+
* @param {object} event The mouse wheel event.
|
|
34881
|
+
*/
|
|
34882
|
+
this.wheel = function (event) {
|
|
34883
|
+
scrollWhell.wheel(event);
|
|
34884
|
+
};
|
|
34885
|
+
|
|
34806
34886
|
/**
|
|
34807
34887
|
* Handle key down event.
|
|
34808
34888
|
*
|
|
@@ -34831,24 +34911,6 @@ dwv.tool.Opacity = function (app) {
|
|
|
34831
34911
|
|
|
34832
34912
|
}; // Opacity class
|
|
34833
34913
|
|
|
34834
|
-
/**
|
|
34835
|
-
* Help for this tool.
|
|
34836
|
-
*
|
|
34837
|
-
* @returns {object} The help content.
|
|
34838
|
-
*/
|
|
34839
|
-
dwv.tool.Opacity.prototype.getHelpKeys = function () {
|
|
34840
|
-
return {
|
|
34841
|
-
title: 'tool.Opacity.name',
|
|
34842
|
-
brief: 'tool.Opacity.brief',
|
|
34843
|
-
mouse: {
|
|
34844
|
-
mouse_drag: 'tool.Opacity.mouse_drag',
|
|
34845
|
-
},
|
|
34846
|
-
touch: {
|
|
34847
|
-
touch_drag: 'tool.Opacity.touch_drag',
|
|
34848
|
-
}
|
|
34849
|
-
};
|
|
34850
|
-
};
|
|
34851
|
-
|
|
34852
34914
|
// namespaces
|
|
34853
34915
|
var dwv = dwv || {};
|
|
34854
34916
|
dwv.tool = dwv.tool || {};
|
|
@@ -36097,11 +36159,11 @@ dwv.tool.Scroll = function (app) {
|
|
|
36097
36159
|
var touchTimerID = null;
|
|
36098
36160
|
|
|
36099
36161
|
/**
|
|
36100
|
-
*
|
|
36162
|
+
* Scroll wheel handler.
|
|
36101
36163
|
*
|
|
36102
|
-
* @type {
|
|
36164
|
+
* @type {dwv.tool.ScrollWheel}
|
|
36103
36165
|
*/
|
|
36104
|
-
var
|
|
36166
|
+
var scrollWhell = new dwv.tool.ScrollWheel(app);
|
|
36105
36167
|
|
|
36106
36168
|
/**
|
|
36107
36169
|
* Option to show or not a value tooltip on mousemove.
|
|
@@ -36266,36 +36328,7 @@ dwv.tool.Scroll = function (app) {
|
|
|
36266
36328
|
* @param {object} event The mouse wheel event.
|
|
36267
36329
|
*/
|
|
36268
36330
|
this.wheel = function (event) {
|
|
36269
|
-
|
|
36270
|
-
// - 0 (DOM_DELTA_PIXEL): chrome, deltaY mouse scroll = 53
|
|
36271
|
-
// - 1 (DOM_DELTA_LINE): firefox, deltaY mouse scroll = 6
|
|
36272
|
-
// - 2 (DOM_DELTA_PAGE): ??
|
|
36273
|
-
// TODO: check scroll event
|
|
36274
|
-
var scrollMin = 52;
|
|
36275
|
-
if (event.deltaMode === 1) {
|
|
36276
|
-
scrollMin = 5.99;
|
|
36277
|
-
}
|
|
36278
|
-
wheelDeltaY += event.deltaY;
|
|
36279
|
-
if (Math.abs(wheelDeltaY) < scrollMin) {
|
|
36280
|
-
return;
|
|
36281
|
-
} else {
|
|
36282
|
-
wheelDeltaY = 0;
|
|
36283
|
-
}
|
|
36284
|
-
|
|
36285
|
-
var up = false;
|
|
36286
|
-
if (event.deltaY < 0) {
|
|
36287
|
-
up = true;
|
|
36288
|
-
}
|
|
36289
|
-
|
|
36290
|
-
var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
|
|
36291
|
-
var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
|
|
36292
|
-
var viewController =
|
|
36293
|
-
layerGroup.getActiveViewLayer().getViewController();
|
|
36294
|
-
if (up) {
|
|
36295
|
-
viewController.incrementScrollIndex();
|
|
36296
|
-
} else {
|
|
36297
|
-
viewController.decrementScrollIndex();
|
|
36298
|
-
}
|
|
36331
|
+
scrollWhell.wheel(event);
|
|
36299
36332
|
};
|
|
36300
36333
|
|
|
36301
36334
|
/**
|
|
@@ -36401,25 +36434,69 @@ dwv.tool.Scroll = function (app) {
|
|
|
36401
36434
|
|
|
36402
36435
|
}; // Scroll class
|
|
36403
36436
|
|
|
36437
|
+
// namespaces
|
|
36438
|
+
var dwv = dwv || {};
|
|
36439
|
+
dwv.tool = dwv.tool || {};
|
|
36440
|
+
|
|
36404
36441
|
/**
|
|
36405
|
-
*
|
|
36442
|
+
* Scroll wheel class: provides a wheel event handler
|
|
36443
|
+
* that scroll the corresponding data.
|
|
36406
36444
|
*
|
|
36407
|
-
* @
|
|
36445
|
+
* @class
|
|
36446
|
+
* @param {dwv.App} app The associated application.
|
|
36408
36447
|
*/
|
|
36409
|
-
dwv.tool.
|
|
36410
|
-
|
|
36411
|
-
|
|
36412
|
-
|
|
36413
|
-
|
|
36414
|
-
|
|
36415
|
-
|
|
36416
|
-
|
|
36417
|
-
|
|
36418
|
-
|
|
36419
|
-
|
|
36448
|
+
dwv.tool.ScrollWheel = function (app) {
|
|
36449
|
+
/**
|
|
36450
|
+
* Accumulated wheel event deltaY.
|
|
36451
|
+
*
|
|
36452
|
+
* @type {number}
|
|
36453
|
+
*/
|
|
36454
|
+
var wheelDeltaY = 0;
|
|
36455
|
+
|
|
36456
|
+
/**
|
|
36457
|
+
* Handle mouse wheel event.
|
|
36458
|
+
*
|
|
36459
|
+
* @param {object} event The mouse wheel event.
|
|
36460
|
+
*/
|
|
36461
|
+
this.wheel = function (event) {
|
|
36462
|
+
// deltaMode (deltaY values on my machine...):
|
|
36463
|
+
// - 0 (DOM_DELTA_PIXEL): chrome, deltaY mouse scroll = 53
|
|
36464
|
+
// - 1 (DOM_DELTA_LINE): firefox, deltaY mouse scroll = 6
|
|
36465
|
+
// - 2 (DOM_DELTA_PAGE): ??
|
|
36466
|
+
// TODO: check scroll event
|
|
36467
|
+
var scrollMin = 52;
|
|
36468
|
+
if (event.deltaMode === 1) {
|
|
36469
|
+
scrollMin = 5.99;
|
|
36470
|
+
}
|
|
36471
|
+
wheelDeltaY += event.deltaY;
|
|
36472
|
+
if (Math.abs(wheelDeltaY) < scrollMin) {
|
|
36473
|
+
return;
|
|
36474
|
+
} else {
|
|
36475
|
+
wheelDeltaY = 0;
|
|
36476
|
+
}
|
|
36477
|
+
|
|
36478
|
+
var up = event.deltaY < 0 ? true : false;
|
|
36479
|
+
|
|
36480
|
+
var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
|
|
36481
|
+
var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
|
|
36482
|
+
var viewController =
|
|
36483
|
+
layerGroup.getActiveViewLayer().getViewController();
|
|
36484
|
+
var imageSize = viewController.getImageSize();
|
|
36485
|
+
if (imageSize.canScroll3D()) {
|
|
36486
|
+
if (up) {
|
|
36487
|
+
viewController.incrementScrollIndex();
|
|
36488
|
+
} else {
|
|
36489
|
+
viewController.decrementScrollIndex();
|
|
36490
|
+
}
|
|
36491
|
+
} else if (imageSize.moreThanOne(3)) {
|
|
36492
|
+
if (up) {
|
|
36493
|
+
viewController.incrementIndex(3);
|
|
36494
|
+
} else {
|
|
36495
|
+
viewController.decrementIndex(3);
|
|
36496
|
+
}
|
|
36420
36497
|
}
|
|
36421
36498
|
};
|
|
36422
|
-
};
|
|
36499
|
+
}; // ScrollWheel class
|
|
36423
36500
|
|
|
36424
36501
|
// namespaces
|
|
36425
36502
|
var dwv = dwv || {};
|
|
@@ -36624,6 +36701,13 @@ dwv.tool.WindowLevel = function (app) {
|
|
|
36624
36701
|
*/
|
|
36625
36702
|
this.started = false;
|
|
36626
36703
|
|
|
36704
|
+
/**
|
|
36705
|
+
* Scroll wheel handler.
|
|
36706
|
+
*
|
|
36707
|
+
* @type {dwv.tool.ScrollWheel}
|
|
36708
|
+
*/
|
|
36709
|
+
var scrollWhell = new dwv.tool.ScrollWheel(app);
|
|
36710
|
+
|
|
36627
36711
|
/**
|
|
36628
36712
|
* Handle mouse down event.
|
|
36629
36713
|
*
|
|
@@ -36756,6 +36840,15 @@ dwv.tool.WindowLevel = function (app) {
|
|
|
36756
36840
|
parseInt(viewController.getWindowLevel().width, 10));
|
|
36757
36841
|
};
|
|
36758
36842
|
|
|
36843
|
+
/**
|
|
36844
|
+
* Handle mouse wheel event.
|
|
36845
|
+
*
|
|
36846
|
+
* @param {object} event The mouse wheel event.
|
|
36847
|
+
*/
|
|
36848
|
+
this.wheel = function (event) {
|
|
36849
|
+
scrollWhell.wheel(event);
|
|
36850
|
+
};
|
|
36851
|
+
|
|
36759
36852
|
/**
|
|
36760
36853
|
* Handle key down event.
|
|
36761
36854
|
*
|
|
@@ -36784,25 +36877,6 @@ dwv.tool.WindowLevel = function (app) {
|
|
|
36784
36877
|
|
|
36785
36878
|
}; // WindowLevel class
|
|
36786
36879
|
|
|
36787
|
-
/**
|
|
36788
|
-
* Help for this tool.
|
|
36789
|
-
*
|
|
36790
|
-
* @returns {object} The help content.
|
|
36791
|
-
*/
|
|
36792
|
-
dwv.tool.WindowLevel.prototype.getHelpKeys = function () {
|
|
36793
|
-
return {
|
|
36794
|
-
title: 'tool.WindowLevel.name',
|
|
36795
|
-
brief: 'tool.WindowLevel.brief',
|
|
36796
|
-
mouse: {
|
|
36797
|
-
mouse_drag: 'tool.WindowLevel.mouse_drag',
|
|
36798
|
-
double_click: 'tool.WindowLevel.double_click'
|
|
36799
|
-
},
|
|
36800
|
-
touch: {
|
|
36801
|
-
touch_drag: 'tool.WindowLevel.touch_drag'
|
|
36802
|
-
}
|
|
36803
|
-
};
|
|
36804
|
-
};
|
|
36805
|
-
|
|
36806
36880
|
// namespaces
|
|
36807
36881
|
var dwv = dwv || {};
|
|
36808
36882
|
dwv.tool = dwv.tool || {};
|
|
@@ -37049,26 +37123,6 @@ dwv.tool.ZoomAndPan = function (app) {
|
|
|
37049
37123
|
|
|
37050
37124
|
}; // ZoomAndPan class
|
|
37051
37125
|
|
|
37052
|
-
/**
|
|
37053
|
-
* Help for this tool.
|
|
37054
|
-
*
|
|
37055
|
-
* @returns {object} The help content.
|
|
37056
|
-
*/
|
|
37057
|
-
dwv.tool.ZoomAndPan.prototype.getHelpKeys = function () {
|
|
37058
|
-
return {
|
|
37059
|
-
title: 'tool.ZoomAndPan.name',
|
|
37060
|
-
brief: 'tool.ZoomAndPan.brief',
|
|
37061
|
-
mouse: {
|
|
37062
|
-
mouse_wheel: 'tool.ZoomAndPan.mouse_wheel',
|
|
37063
|
-
mouse_drag: 'tool.ZoomAndPan.mouse_drag'
|
|
37064
|
-
},
|
|
37065
|
-
touch: {
|
|
37066
|
-
twotouch_pinch: 'tool.ZoomAndPan.twotouch_pinch',
|
|
37067
|
-
touch_drag: 'tool.ZoomAndPan.touch_drag'
|
|
37068
|
-
}
|
|
37069
|
-
};
|
|
37070
|
-
};
|
|
37071
|
-
|
|
37072
37126
|
/**
|
|
37073
37127
|
* Initialise the tool.
|
|
37074
37128
|
*/
|
|
@@ -37979,189 +38033,29 @@ dwv.env.check = function () {
|
|
|
37979
38033
|
|
|
37980
38034
|
// namespaces
|
|
37981
38035
|
var dwv = dwv || {};
|
|
37982
|
-
/**
|
|
37983
|
-
* The i18next namespace.
|
|
37984
|
-
*
|
|
37985
|
-
* @external i18next
|
|
37986
|
-
* @see https://www.i18next.com
|
|
37987
|
-
*/
|
|
37988
|
-
var i18next = i18next || {};
|
|
37989
|
-
/**
|
|
37990
|
-
* The i18nextHttpBackend namespace.
|
|
37991
|
-
*
|
|
37992
|
-
* @external i18nextHttpBackend
|
|
37993
|
-
* @see https://github.com/i18next/i18next-http-backend
|
|
37994
|
-
*/
|
|
37995
|
-
var i18nextHttpBackend = i18nextHttpBackend || {};
|
|
37996
|
-
/**
|
|
37997
|
-
* The i18nextBrowserLanguageDetector namespace.
|
|
37998
|
-
*
|
|
37999
|
-
* @external i18nextBrowserLanguageDetector
|
|
38000
|
-
* @see https://github.com/i18next/i18next-browser-languageDetector
|
|
38001
|
-
*/
|
|
38002
|
-
var i18nextBrowserLanguageDetector = i18nextBrowserLanguageDetector || {};
|
|
38003
|
-
|
|
38004
|
-
// This is mainly a wrapper around the i18next object.
|
|
38005
|
-
// see its API: http://i18next.com/docs/api/
|
|
38006
|
-
|
|
38007
|
-
// global locales path
|
|
38008
|
-
dwv.i18nLocalesPath = null;
|
|
38009
|
-
|
|
38010
|
-
/**
|
|
38011
|
-
* Initialise i18n.
|
|
38012
|
-
*
|
|
38013
|
-
* @param {string} language The language to translate to. Defaults to 'auto' and
|
|
38014
|
-
* gets the language from the browser.
|
|
38015
|
-
* @param {string} localesPath Path to the locales directory.
|
|
38016
|
-
*/
|
|
38017
|
-
dwv.i18nInitialise = function (language, localesPath) {
|
|
38018
|
-
var lng = (typeof language === 'undefined') ? 'auto' : language;
|
|
38019
|
-
var lpath = (typeof localesPath === 'undefined') ? '../..' : localesPath;
|
|
38020
|
-
// store as global
|
|
38021
|
-
dwv.i18nLocalesPath = lpath;
|
|
38022
|
-
// i18n options: default 'en' language and
|
|
38023
|
-
// only load language, not specialised (for ex en-GB)
|
|
38024
|
-
var options = {
|
|
38025
|
-
fallbackLng: 'en',
|
|
38026
|
-
load: 'languageOnly',
|
|
38027
|
-
backend: {loadPath: lpath + '/locales/{{lng}}/{{ns}}.json'}
|
|
38028
|
-
};
|
|
38029
|
-
// use the HTTP backend to get translation files
|
|
38030
|
-
var i18n = i18next.use(i18nextHttpBackend);
|
|
38031
|
-
// use browser language or the specified one
|
|
38032
|
-
if (lng === 'auto') {
|
|
38033
|
-
i18n.use(i18nextBrowserLanguageDetector);
|
|
38034
|
-
} else {
|
|
38035
|
-
options.lng = lng;
|
|
38036
|
-
}
|
|
38037
|
-
// init i18n: will be ready when the 'loaded' event is fired
|
|
38038
|
-
i18n.init(options);
|
|
38039
|
-
};
|
|
38040
|
-
|
|
38041
|
-
/**
|
|
38042
|
-
* Initialise i18n with recources as input.
|
|
38043
|
-
*
|
|
38044
|
-
* @param {string} language The language to translate to. Defaults to 'auto' and
|
|
38045
|
-
* gets the language from the browser.
|
|
38046
|
-
* @param {object} resources Languages provided as object.
|
|
38047
|
-
*/
|
|
38048
|
-
dwv.i18nInitialiseWithResources = function (language, resources) {
|
|
38049
|
-
var lng = (typeof language === 'undefined') ? 'auto' : language;
|
|
38050
|
-
// i18n options: default 'en' language and
|
|
38051
|
-
// only load language, not specialised (for ex en-GB)
|
|
38052
|
-
var options = {
|
|
38053
|
-
fallbackLng: 'en',
|
|
38054
|
-
load: 'languageOnly',
|
|
38055
|
-
resources: resources
|
|
38056
|
-
};
|
|
38057
|
-
// use browser language or the specified one
|
|
38058
|
-
// init i18n: will be ready when the 'loaded' event is fired
|
|
38059
|
-
if (lng === 'auto') {
|
|
38060
|
-
var i18n = i18next.use(i18nextBrowserLanguageDetector);
|
|
38061
|
-
i18n.init(options);
|
|
38062
|
-
} else {
|
|
38063
|
-
options.lng = lng;
|
|
38064
|
-
i18next.init(options);
|
|
38065
|
-
}
|
|
38066
|
-
};
|
|
38067
|
-
|
|
38068
|
-
/**
|
|
38069
|
-
* Handle i18n 'initialized' event.
|
|
38070
|
-
*
|
|
38071
|
-
* @param {object} callback The callback function to call when i18n
|
|
38072
|
-
* is initialised.
|
|
38073
|
-
* It can take one argument that will be replaced with the i18n options.
|
|
38074
|
-
*/
|
|
38075
|
-
dwv.i18nOnInitialised = function (callback) {
|
|
38076
|
-
i18next.on('initialized', callback);
|
|
38077
|
-
};
|
|
38078
|
-
|
|
38079
|
-
/**
|
|
38080
|
-
* Stop handling i18n load event.
|
|
38081
|
-
*/
|
|
38082
|
-
dwv.i18nOffInitialised = function () {
|
|
38083
|
-
i18next.off('initialized');
|
|
38084
|
-
};
|
|
38085
|
-
|
|
38086
|
-
/**
|
|
38087
|
-
* Handle i18n failed load event.
|
|
38088
|
-
*
|
|
38089
|
-
* @param {object} callback The callback function to call when i18n is loaded.
|
|
38090
|
-
* It can take three arguments: lng, ns and msg.
|
|
38091
|
-
*/
|
|
38092
|
-
dwv.i18nOnFailedLoad = function (callback) {
|
|
38093
|
-
i18next.on('failedLoading', callback);
|
|
38094
|
-
};
|
|
38095
|
-
|
|
38096
|
-
/**
|
|
38097
|
-
* Stop handling i18n failed load event.
|
|
38098
|
-
*/
|
|
38099
|
-
dwv.i18nOffFailedLoad = function () {
|
|
38100
|
-
i18next.off('failedLoading');
|
|
38101
|
-
};
|
|
38102
38036
|
|
|
38103
38037
|
/**
|
|
38104
38038
|
* Get the translated text.
|
|
38105
38039
|
*
|
|
38106
38040
|
* @param {string} key The key to the text entry.
|
|
38107
|
-
* @param {object}
|
|
38108
|
-
* @returns {string} The translated text.
|
|
38041
|
+
* @param {object} _options The translation options such as plural, context...
|
|
38042
|
+
* @returns {string|undefined} The translated text.
|
|
38109
38043
|
*/
|
|
38110
|
-
dwv.i18n = function (key,
|
|
38111
|
-
|
|
38112
|
-
|
|
38113
|
-
|
|
38114
|
-
|
|
38115
|
-
|
|
38116
|
-
|
|
38117
|
-
|
|
38118
|
-
|
|
38119
|
-
|
|
38120
|
-
*/
|
|
38121
|
-
dwv.i18nExists = function (key, options) {
|
|
38122
|
-
return i18next.exists(key, options);
|
|
38123
|
-
};
|
|
38124
|
-
|
|
38125
|
-
/**
|
|
38126
|
-
* Translate all data-i18n tags in the current html page. If an html tag defines
|
|
38127
|
-
* the data-i18n attribute, its value will be used as key to find its
|
|
38128
|
-
* corresponding text and will replace the content of the html tag.
|
|
38129
|
-
*/
|
|
38130
|
-
dwv.i18nPage = function () {
|
|
38131
|
-
// get all elements
|
|
38132
|
-
var elements = document.getElementsByTagName('*');
|
|
38133
|
-
// if the element defines data-i18n, replace its content with the tranlation
|
|
38134
|
-
for (var i = 0; i < elements.length; ++i) {
|
|
38135
|
-
if (typeof elements[i].dataset.i18n !== 'undefined') {
|
|
38136
|
-
elements[i].innerHTML = dwv.i18n(elements[i].dataset.i18n);
|
|
38137
|
-
}
|
|
38044
|
+
dwv.i18n = function (key, _options) {
|
|
38045
|
+
// defaut expects something like 'unit.cm2'
|
|
38046
|
+
var unit = {
|
|
38047
|
+
mm: 'mm',
|
|
38048
|
+
cm2: 'cm²',
|
|
38049
|
+
degree: '°'
|
|
38050
|
+
};
|
|
38051
|
+
var props = key.split('.');
|
|
38052
|
+
if (props.length !== 2) {
|
|
38053
|
+
throw new Error('Unexpected translation key length.');
|
|
38138
38054
|
}
|
|
38139
|
-
|
|
38140
|
-
|
|
38141
|
-
|
|
38142
|
-
|
|
38143
|
-
* Warning: to be used once i18next is initialised.
|
|
38144
|
-
*
|
|
38145
|
-
* @param {string} filename The file to locate.
|
|
38146
|
-
* @returns {string} The path to the locale resource.
|
|
38147
|
-
*/
|
|
38148
|
-
dwv.i18nGetLocalePath = function (filename) {
|
|
38149
|
-
var lng = i18next.language.substring(0, 2);
|
|
38150
|
-
return dwv.i18nLocalesPath +
|
|
38151
|
-
'/locales/' + lng + '/' + filename;
|
|
38152
|
-
};
|
|
38153
|
-
|
|
38154
|
-
/**
|
|
38155
|
-
* Get the current locale resource path.
|
|
38156
|
-
* Warning: to be used once i18next is initialised.
|
|
38157
|
-
*
|
|
38158
|
-
* @param {string} filename The file to locate.
|
|
38159
|
-
* @returns {string} The path to the locale resource.
|
|
38160
|
-
*/
|
|
38161
|
-
dwv.i18nGetFallbackLocalePath = function (filename) {
|
|
38162
|
-
var lng = i18next.languages[i18next.languages.length - 1].substring(0, 2);
|
|
38163
|
-
return dwv.i18nLocalesPath +
|
|
38164
|
-
'/locales/' + lng + '/' + filename;
|
|
38055
|
+
if (props[0] !== 'unit') {
|
|
38056
|
+
throw new Error('Unexpected translation key prefix.');
|
|
38057
|
+
}
|
|
38058
|
+
return unit[props[1]];
|
|
38165
38059
|
};
|
|
38166
38060
|
|
|
38167
38061
|
// namespaces
|