@excalidraw/common 0.18.0-5fffc47 → 0.18.0-6135548
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/dev/index.js +1299 -256
- package/dist/dev/index.js.map +4 -4
- package/dist/prod/index.js +3 -3
- package/dist/types/common/src/bounds.d.ts +10 -0
- package/dist/types/common/src/colors.d.ts +59 -39
- package/dist/types/common/src/constants.d.ts +16 -28
- package/dist/types/common/src/editorInterface.d.ts +34 -0
- package/dist/types/common/src/font-metadata.d.ts +1 -3
- package/dist/types/common/src/index.d.ts +2 -0
- package/dist/types/common/src/keys.d.ts +1 -1
- package/dist/types/common/src/utility-types.d.ts +0 -1
- package/dist/types/common/src/utils.d.ts +48 -36
- package/dist/types/element/src/Scene.d.ts +4 -4
- package/dist/types/element/src/binding.d.ts +58 -44
- package/dist/types/element/src/bounds.d.ts +2 -10
- package/dist/types/element/src/collision.d.ts +6 -2
- package/dist/types/element/src/comparisons.d.ts +7 -7
- package/dist/types/element/src/dragElements.d.ts +3 -3
- package/dist/types/element/src/duplicate.d.ts +3 -3
- package/dist/types/element/src/fractionalIndex.d.ts +2 -2
- package/dist/types/element/src/frame.d.ts +7 -3
- package/dist/types/element/src/heading.d.ts +2 -1
- package/dist/types/element/src/image.d.ts +1 -11
- package/dist/types/element/src/index.d.ts +1 -3
- package/dist/types/element/src/linearElementEditor.d.ts +16 -20
- package/dist/types/element/src/mutateElement.d.ts +3 -1
- package/dist/types/element/src/newElement.d.ts +6 -6
- package/dist/types/element/src/renderElement.d.ts +1 -7
- package/dist/types/element/src/resizeElements.d.ts +10 -10
- package/dist/types/element/src/resizeTest.d.ts +6 -5
- package/dist/types/element/src/selection.d.ts +3 -7
- package/dist/types/element/src/shape.d.ts +8 -7
- package/dist/types/element/src/textMeasurements.d.ts +1 -3
- package/dist/types/{excalidraw/data → element/src}/transform.d.ts +3 -3
- package/dist/types/element/src/transformHandles.d.ts +8 -27
- package/dist/types/element/src/typeChecks.d.ts +4 -7
- package/dist/types/element/src/types.d.ts +7 -11
- package/dist/types/element/src/utils.d.ts +5 -2
- package/dist/types/element/src/zindex.d.ts +7 -1
- package/dist/types/excalidraw/actions/actionAddToLibrary.d.ts +123 -181
- package/dist/types/excalidraw/actions/actionAlign.d.ts +6 -7
- package/dist/types/excalidraw/actions/actionBoundText.d.ts +57 -96
- package/dist/types/excalidraw/actions/actionCanvas.d.ts +341 -763
- package/dist/types/excalidraw/actions/actionClipboard.d.ts +93 -893
- package/dist/types/excalidraw/actions/actionCropEditor.d.ts +27 -47
- package/dist/types/excalidraw/actions/actionDeleteSelected.d.ts +95 -159
- package/dist/types/excalidraw/actions/actionDistribute.d.ts +2 -3
- package/dist/types/excalidraw/actions/actionDuplicateSelection.d.ts +3 -4
- package/dist/types/excalidraw/actions/actionElementLink.d.ts +42 -64
- package/dist/types/excalidraw/actions/actionElementLock.d.ts +56 -95
- package/dist/types/excalidraw/actions/actionEmbeddable.d.ts +44 -64
- package/dist/types/excalidraw/actions/actionExport.d.ts +124 -1129
- package/dist/types/excalidraw/actions/actionFinalize.d.ts +10 -404
- package/dist/types/excalidraw/actions/actionFlip.d.ts +2 -3
- package/dist/types/excalidraw/actions/actionFrame.d.ts +232 -347
- package/dist/types/excalidraw/actions/actionGroup.d.ts +60 -107
- package/dist/types/excalidraw/actions/actionLinearEditor.d.ts +159 -219
- package/dist/types/excalidraw/actions/actionLink.d.ts +45 -65
- package/dist/types/excalidraw/actions/actionMenu.d.ts +36 -58
- package/dist/types/excalidraw/actions/actionNavigate.d.ts +18 -369
- package/dist/types/excalidraw/actions/actionProperties.d.ts +117 -2560
- package/dist/types/excalidraw/actions/actionSelectAll.d.ts +30 -54
- package/dist/types/excalidraw/actions/actionStyles.d.ts +27 -47
- package/dist/types/excalidraw/actions/actionTextAutoResize.d.ts +3 -3
- package/dist/types/excalidraw/actions/actionToggleGridMode.d.ts +44 -64
- package/dist/types/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +44 -64
- package/dist/types/excalidraw/actions/actionToggleSearchMenu.d.ts +36 -58
- package/dist/types/excalidraw/actions/actionToggleShapeSwitch.d.ts +1 -1
- package/dist/types/excalidraw/actions/actionToggleStats.d.ts +43 -63
- package/dist/types/excalidraw/actions/actionToggleViewMode.d.ts +44 -64
- package/dist/types/excalidraw/actions/actionToggleZenMode.d.ts +44 -64
- package/dist/types/excalidraw/actions/actionZindex.d.ts +8 -9
- package/dist/types/excalidraw/actions/register.d.ts +2 -2
- package/dist/types/excalidraw/actions/types.d.ts +3 -3
- package/dist/types/excalidraw/appState.d.ts +15 -14
- package/dist/types/excalidraw/clipboard.d.ts +7 -31
- package/dist/types/excalidraw/components/Actions.d.ts +5 -2
- package/dist/types/excalidraw/components/App.d.ts +58 -58
- package/dist/types/excalidraw/components/Card.d.ts +1 -3
- package/dist/types/excalidraw/components/ColorPicker/ColorInput.d.ts +2 -4
- package/dist/types/excalidraw/components/ColorPicker/ColorPicker.d.ts +0 -2
- package/dist/types/excalidraw/components/ColorPicker/colorPickerUtils.d.ts +0 -1
- package/dist/types/excalidraw/components/ColorPicker/keyboardNavHandlers.d.ts +0 -1
- package/dist/types/excalidraw/components/CommandPalette/types.d.ts +1 -3
- package/dist/types/excalidraw/components/ConvertElementTypePopup.d.ts +2 -2
- package/dist/types/excalidraw/components/DarkModeToggle.d.ts +1 -1
- package/dist/types/excalidraw/components/DefaultSidebar.d.ts +9 -13
- package/dist/types/excalidraw/components/ElementLinkDialog.d.ts +1 -1
- package/dist/types/excalidraw/components/Ellipsify.d.ts +1 -2
- package/dist/types/excalidraw/components/ErrorDialog.d.ts +1 -1
- package/dist/types/excalidraw/components/ExcalidrawLogo.d.ts +0 -1
- package/dist/types/excalidraw/components/EyeDropper.d.ts +0 -1
- package/dist/types/excalidraw/components/FilledButton.d.ts +2 -1
- package/dist/types/excalidraw/components/FontPicker/keyboardNavHandlers.d.ts +0 -1
- package/dist/types/excalidraw/components/HelpDialog.d.ts +1 -1
- package/dist/types/excalidraw/components/HintViewer.d.ts +4 -3
- package/dist/types/excalidraw/components/InlineIcon.d.ts +2 -2
- package/dist/types/excalidraw/components/LibraryMenuControlButtons.d.ts +1 -1
- package/dist/types/excalidraw/components/LibraryMenuHeaderContent.d.ts +1 -2
- package/dist/types/excalidraw/components/LibraryUnit.d.ts +2 -3
- package/dist/types/excalidraw/components/LoadingMessage.d.ts +0 -1
- package/dist/types/excalidraw/components/MobileMenu.d.ts +1 -1
- package/dist/types/excalidraw/components/MobileToolBar.d.ts +0 -1
- package/dist/types/excalidraw/components/Modal.d.ts +0 -1
- package/dist/types/excalidraw/components/OverwriteConfirm/OverwriteConfirm.d.ts +1 -1
- package/dist/types/excalidraw/components/Popover.d.ts +2 -1
- package/dist/types/excalidraw/components/RadioGroup.d.ts +0 -1
- package/dist/types/excalidraw/components/RadioSelection.d.ts +4 -4
- package/dist/types/excalidraw/components/ScrollableList.d.ts +0 -1
- package/dist/types/excalidraw/components/Sidebar/Sidebar.d.ts +15 -21
- package/dist/types/excalidraw/components/Sidebar/SidebarHeader.d.ts +1 -1
- package/dist/types/excalidraw/components/Sidebar/SidebarTab.d.ts +1 -2
- package/dist/types/excalidraw/components/Sidebar/SidebarTabTrigger.d.ts +1 -2
- package/dist/types/excalidraw/components/Sidebar/SidebarTabTriggers.d.ts +1 -2
- package/dist/types/excalidraw/components/Sidebar/SidebarTabs.d.ts +1 -2
- package/dist/types/excalidraw/components/Spinner.d.ts +4 -4
- package/dist/types/excalidraw/components/Stats/CanvasGrid.d.ts +0 -1
- package/dist/types/excalidraw/components/Stats/Collapsible.d.ts +0 -1
- package/dist/types/excalidraw/components/Stats/DragInput.d.ts +0 -1
- package/dist/types/excalidraw/components/Stats/index.d.ts +7 -8
- package/dist/types/excalidraw/components/Stats/utils.d.ts +1 -1
- package/dist/types/excalidraw/components/TTDDialog/Chat/ChatHistoryMenu.d.ts +15 -0
- package/dist/types/excalidraw/components/TTDDialog/Chat/ChatInterface.d.ts +27 -0
- package/dist/types/excalidraw/components/TTDDialog/Chat/ChatMessage.d.ts +14 -0
- package/dist/types/excalidraw/components/TTDDialog/Chat/TTDChatPanel.d.ts +26 -0
- package/dist/types/excalidraw/components/TTDDialog/Chat/index.d.ts +3 -0
- package/dist/types/excalidraw/components/TTDDialog/Chat/useChatAgent.d.ts +8 -0
- package/dist/types/excalidraw/components/TTDDialog/MermaidToExcalidraw.d.ts +3 -2
- package/dist/types/excalidraw/components/TTDDialog/TTDContext.d.ts +13 -0
- package/dist/types/excalidraw/components/TTDDialog/TTDDialog.d.ts +4 -25
- package/dist/types/excalidraw/components/TTDDialog/TTDDialogOutput.d.ts +2 -2
- package/dist/types/excalidraw/components/TTDDialog/TTDDialogPanel.d.ts +13 -9
- package/dist/types/excalidraw/components/TTDDialog/TTDDialogTab.d.ts +1 -2
- package/dist/types/excalidraw/components/TTDDialog/TTDDialogTabTrigger.d.ts +1 -2
- package/dist/types/excalidraw/components/TTDDialog/TTDDialogTabTriggers.d.ts +1 -2
- package/dist/types/excalidraw/components/TTDDialog/TTDDialogTrigger.d.ts +1 -1
- package/dist/types/excalidraw/components/TTDDialog/TTDPreviewPanel.d.ts +9 -0
- package/dist/types/excalidraw/components/TTDDialog/TextToDiagram.d.ts +8 -0
- package/dist/types/excalidraw/components/TTDDialog/common.d.ts +16 -16
- package/dist/types/excalidraw/components/TTDDialog/hooks/useChatManagement.d.ts +13 -0
- package/dist/types/excalidraw/components/TTDDialog/hooks/useMermaidRenderer.d.ts +14 -0
- package/dist/types/excalidraw/components/TTDDialog/hooks/useTextGeneration.d.ts +7 -0
- package/dist/types/excalidraw/components/TTDDialog/types.d.ts +91 -0
- package/dist/types/excalidraw/components/TTDDialog/useTTDChatStorage.d.ts +22 -0
- package/dist/types/excalidraw/components/TTDDialog/utils/TTDStreamFetch.d.ts +24 -0
- package/dist/types/excalidraw/components/TTDDialog/utils/chat.d.ts +10 -0
- package/dist/types/excalidraw/components/TTDDialog/utils/mermaidValidation.d.ts +1 -0
- package/dist/types/excalidraw/components/Toast.d.ts +3 -3
- package/dist/types/excalidraw/components/Trans.d.ts +2 -2
- package/dist/types/excalidraw/components/canvases/InteractiveCanvas.d.ts +6 -3
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenu.d.ts +30 -33
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuContent.d.ts +5 -5
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuGroup.d.ts +3 -3
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItem.d.ts +12 -19
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItemContent.d.ts +5 -4
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItemContentRadio.d.ts +0 -1
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItemCustom.d.ts +2 -2
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItemLink.d.ts +6 -6
- package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuTrigger.d.ts +3 -4
- package/dist/types/excalidraw/components/dropdownMenu/common.d.ts +1 -1
- package/dist/types/excalidraw/components/hoc/withInternalFallback.d.ts +1 -1
- package/dist/types/excalidraw/components/hyperlink/helpers.d.ts +1 -1
- package/dist/types/excalidraw/components/icons.d.ts +21 -12
- package/dist/types/excalidraw/components/live-collaboration/LiveCollaborationTrigger.d.ts +4 -3
- package/dist/types/excalidraw/components/main-menu/DefaultItems.d.ts +2 -2
- package/dist/types/excalidraw/components/main-menu/MainMenu.d.ts +26 -32
- package/dist/types/excalidraw/components/shapes.d.ts +1 -1
- package/dist/types/excalidraw/components/welcome-screen/WelcomeScreen.Center.d.ts +6 -6
- package/dist/types/excalidraw/components/welcome-screen/WelcomeScreen.d.ts +15 -16
- package/dist/types/excalidraw/data/blob.d.ts +321 -3
- package/dist/types/excalidraw/data/encode.d.ts +4 -4
- package/dist/types/excalidraw/data/encryption.d.ts +5 -5
- package/dist/types/excalidraw/data/filesystem.d.ts +2 -2
- package/dist/types/excalidraw/data/index.d.ts +3 -3
- package/dist/types/excalidraw/data/json.d.ts +159 -2
- package/dist/types/excalidraw/data/library.d.ts +24 -9
- package/dist/types/excalidraw/data/restore.d.ts +25 -10
- package/dist/types/excalidraw/editor-jotai.d.ts +11 -11
- package/dist/types/excalidraw/errors.d.ts +14 -0
- package/dist/types/excalidraw/hooks/useOutsideClick.d.ts +4 -3
- package/dist/types/excalidraw/hooks/useScrollPosition.d.ts +1 -2
- package/dist/types/excalidraw/i18n.d.ts +2 -2
- package/dist/types/excalidraw/index.d.ts +6 -7
- package/dist/types/excalidraw/renderer/animation.d.ts +12 -0
- package/dist/types/excalidraw/renderer/helpers.d.ts +6 -8
- package/dist/types/excalidraw/renderer/interactiveScene.d.ts +8 -14
- package/dist/types/excalidraw/scene/Renderer.d.ts +5 -2
- package/dist/types/excalidraw/scene/export.d.ts +2 -2
- package/dist/types/excalidraw/scene/scroll.d.ts +1 -6
- package/dist/types/excalidraw/scene/types.d.ts +22 -5
- package/dist/types/excalidraw/shortcut.d.ts +1 -0
- package/dist/types/excalidraw/snapping.d.ts +5 -5
- package/dist/types/excalidraw/subset/harfbuzz/harfbuzz-bindings.d.ts +1 -1
- package/dist/types/excalidraw/subset/harfbuzz/harfbuzz-loader.d.ts +1 -1
- package/dist/types/excalidraw/subset/harfbuzz/harfbuzz-wasm.d.ts +1 -1
- package/dist/types/excalidraw/subset/woff2/woff2-loader.d.ts +2 -2
- package/dist/types/excalidraw/subset/woff2/woff2-wasm.d.ts +1 -1
- package/dist/types/excalidraw/types.d.ts +22 -20
- package/dist/types/excalidraw/wysiwyg/textWysiwyg.d.ts +2 -2
- package/dist/types/math/src/polygon.d.ts +2 -2
- package/dist/types/math/src/range.d.ts +1 -3
- package/dist/types/math/src/segment.d.ts +3 -3
- package/dist/types/utils/src/bbox.d.ts +1 -1
- package/dist/types/utils/src/export.d.ts +5 -5
- package/dist/types/utils/src/shape.d.ts +6 -6
- package/dist/types/utils/src/withinBounds.d.ts +2 -2
- package/package.json +7 -1
package/dist/dev/index.js
CHANGED
|
@@ -363,173 +363,1058 @@ var BinaryHeap = class {
|
|
|
363
363
|
}
|
|
364
364
|
};
|
|
365
365
|
|
|
366
|
+
// src/bounds.ts
|
|
367
|
+
init_define_import_meta_env();
|
|
368
|
+
var isBounds = (box) => Array.isArray(box) && box.length === 4 && typeof box[0] === "number" && typeof box[1] === "number" && typeof box[2] === "number" && typeof box[3] === "number";
|
|
369
|
+
|
|
366
370
|
// src/colors.ts
|
|
367
371
|
init_define_import_meta_env();
|
|
368
372
|
|
|
369
|
-
// ../../node_modules/
|
|
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
|
-
|
|
373
|
+
// ../../node_modules/tinycolor2/esm/tinycolor.js
|
|
374
|
+
init_define_import_meta_env();
|
|
375
|
+
function _typeof(obj) {
|
|
376
|
+
"@babel/helpers - typeof";
|
|
377
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) {
|
|
378
|
+
return typeof obj2;
|
|
379
|
+
} : function(obj2) {
|
|
380
|
+
return obj2 && "function" == typeof Symbol && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
|
|
381
|
+
}, _typeof(obj);
|
|
382
|
+
}
|
|
383
|
+
var trimLeft = /^\s+/;
|
|
384
|
+
var trimRight = /\s+$/;
|
|
385
|
+
function tinycolor(color, opts) {
|
|
386
|
+
color = color ? color : "";
|
|
387
|
+
opts = opts || {};
|
|
388
|
+
if (color instanceof tinycolor) {
|
|
389
|
+
return color;
|
|
390
|
+
}
|
|
391
|
+
if (!(this instanceof tinycolor)) {
|
|
392
|
+
return new tinycolor(color, opts);
|
|
393
|
+
}
|
|
394
|
+
var rgb = inputToRGB(color);
|
|
395
|
+
this._originalInput = color, this._r = rgb.r, this._g = rgb.g, this._b = rgb.b, this._a = rgb.a, this._roundA = Math.round(100 * this._a) / 100, this._format = opts.format || rgb.format;
|
|
396
|
+
this._gradientType = opts.gradientType;
|
|
397
|
+
if (this._r < 1)
|
|
398
|
+
this._r = Math.round(this._r);
|
|
399
|
+
if (this._g < 1)
|
|
400
|
+
this._g = Math.round(this._g);
|
|
401
|
+
if (this._b < 1)
|
|
402
|
+
this._b = Math.round(this._b);
|
|
403
|
+
this._ok = rgb.ok;
|
|
404
|
+
}
|
|
405
|
+
tinycolor.prototype = {
|
|
406
|
+
isDark: function isDark() {
|
|
407
|
+
return this.getBrightness() < 128;
|
|
408
|
+
},
|
|
409
|
+
isLight: function isLight() {
|
|
410
|
+
return !this.isDark();
|
|
411
|
+
},
|
|
412
|
+
isValid: function isValid() {
|
|
413
|
+
return this._ok;
|
|
414
|
+
},
|
|
415
|
+
getOriginalInput: function getOriginalInput() {
|
|
416
|
+
return this._originalInput;
|
|
417
|
+
},
|
|
418
|
+
getFormat: function getFormat() {
|
|
419
|
+
return this._format;
|
|
420
|
+
},
|
|
421
|
+
getAlpha: function getAlpha() {
|
|
422
|
+
return this._a;
|
|
423
|
+
},
|
|
424
|
+
getBrightness: function getBrightness() {
|
|
425
|
+
var rgb = this.toRgb();
|
|
426
|
+
return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1e3;
|
|
427
|
+
},
|
|
428
|
+
getLuminance: function getLuminance() {
|
|
429
|
+
var rgb = this.toRgb();
|
|
430
|
+
var RsRGB, GsRGB, BsRGB, R, G, B;
|
|
431
|
+
RsRGB = rgb.r / 255;
|
|
432
|
+
GsRGB = rgb.g / 255;
|
|
433
|
+
BsRGB = rgb.b / 255;
|
|
434
|
+
if (RsRGB <= 0.03928)
|
|
435
|
+
R = RsRGB / 12.92;
|
|
436
|
+
else
|
|
437
|
+
R = Math.pow((RsRGB + 0.055) / 1.055, 2.4);
|
|
438
|
+
if (GsRGB <= 0.03928)
|
|
439
|
+
G = GsRGB / 12.92;
|
|
440
|
+
else
|
|
441
|
+
G = Math.pow((GsRGB + 0.055) / 1.055, 2.4);
|
|
442
|
+
if (BsRGB <= 0.03928)
|
|
443
|
+
B = BsRGB / 12.92;
|
|
444
|
+
else
|
|
445
|
+
B = Math.pow((BsRGB + 0.055) / 1.055, 2.4);
|
|
446
|
+
return 0.2126 * R + 0.7152 * G + 0.0722 * B;
|
|
447
|
+
},
|
|
448
|
+
setAlpha: function setAlpha(value) {
|
|
449
|
+
this._a = boundAlpha(value);
|
|
450
|
+
this._roundA = Math.round(100 * this._a) / 100;
|
|
451
|
+
return this;
|
|
452
|
+
},
|
|
453
|
+
toHsv: function toHsv() {
|
|
454
|
+
var hsv = rgbToHsv(this._r, this._g, this._b);
|
|
455
|
+
return {
|
|
456
|
+
h: hsv.h * 360,
|
|
457
|
+
s: hsv.s,
|
|
458
|
+
v: hsv.v,
|
|
459
|
+
a: this._a
|
|
460
|
+
};
|
|
461
|
+
},
|
|
462
|
+
toHsvString: function toHsvString() {
|
|
463
|
+
var hsv = rgbToHsv(this._r, this._g, this._b);
|
|
464
|
+
var h = Math.round(hsv.h * 360), s = Math.round(hsv.s * 100), v = Math.round(hsv.v * 100);
|
|
465
|
+
return this._a == 1 ? "hsv(" + h + ", " + s + "%, " + v + "%)" : "hsva(" + h + ", " + s + "%, " + v + "%, " + this._roundA + ")";
|
|
466
|
+
},
|
|
467
|
+
toHsl: function toHsl() {
|
|
468
|
+
var hsl = rgbToHsl(this._r, this._g, this._b);
|
|
469
|
+
return {
|
|
470
|
+
h: hsl.h * 360,
|
|
471
|
+
s: hsl.s,
|
|
472
|
+
l: hsl.l,
|
|
473
|
+
a: this._a
|
|
474
|
+
};
|
|
475
|
+
},
|
|
476
|
+
toHslString: function toHslString() {
|
|
477
|
+
var hsl = rgbToHsl(this._r, this._g, this._b);
|
|
478
|
+
var h = Math.round(hsl.h * 360), s = Math.round(hsl.s * 100), l = Math.round(hsl.l * 100);
|
|
479
|
+
return this._a == 1 ? "hsl(" + h + ", " + s + "%, " + l + "%)" : "hsla(" + h + ", " + s + "%, " + l + "%, " + this._roundA + ")";
|
|
480
|
+
},
|
|
481
|
+
toHex: function toHex(allow3Char) {
|
|
482
|
+
return rgbToHex(this._r, this._g, this._b, allow3Char);
|
|
483
|
+
},
|
|
484
|
+
toHexString: function toHexString(allow3Char) {
|
|
485
|
+
return "#" + this.toHex(allow3Char);
|
|
486
|
+
},
|
|
487
|
+
toHex8: function toHex8(allow4Char) {
|
|
488
|
+
return rgbaToHex(this._r, this._g, this._b, this._a, allow4Char);
|
|
489
|
+
},
|
|
490
|
+
toHex8String: function toHex8String(allow4Char) {
|
|
491
|
+
return "#" + this.toHex8(allow4Char);
|
|
492
|
+
},
|
|
493
|
+
toRgb: function toRgb() {
|
|
494
|
+
return {
|
|
495
|
+
r: Math.round(this._r),
|
|
496
|
+
g: Math.round(this._g),
|
|
497
|
+
b: Math.round(this._b),
|
|
498
|
+
a: this._a
|
|
499
|
+
};
|
|
500
|
+
},
|
|
501
|
+
toRgbString: function toRgbString() {
|
|
502
|
+
return this._a == 1 ? "rgb(" + Math.round(this._r) + ", " + Math.round(this._g) + ", " + Math.round(this._b) + ")" : "rgba(" + Math.round(this._r) + ", " + Math.round(this._g) + ", " + Math.round(this._b) + ", " + this._roundA + ")";
|
|
503
|
+
},
|
|
504
|
+
toPercentageRgb: function toPercentageRgb() {
|
|
505
|
+
return {
|
|
506
|
+
r: Math.round(bound01(this._r, 255) * 100) + "%",
|
|
507
|
+
g: Math.round(bound01(this._g, 255) * 100) + "%",
|
|
508
|
+
b: Math.round(bound01(this._b, 255) * 100) + "%",
|
|
509
|
+
a: this._a
|
|
510
|
+
};
|
|
511
|
+
},
|
|
512
|
+
toPercentageRgbString: function toPercentageRgbString() {
|
|
513
|
+
return this._a == 1 ? "rgb(" + Math.round(bound01(this._r, 255) * 100) + "%, " + Math.round(bound01(this._g, 255) * 100) + "%, " + Math.round(bound01(this._b, 255) * 100) + "%)" : "rgba(" + Math.round(bound01(this._r, 255) * 100) + "%, " + Math.round(bound01(this._g, 255) * 100) + "%, " + Math.round(bound01(this._b, 255) * 100) + "%, " + this._roundA + ")";
|
|
514
|
+
},
|
|
515
|
+
toName: function toName() {
|
|
516
|
+
if (this._a === 0) {
|
|
517
|
+
return "transparent";
|
|
518
|
+
}
|
|
519
|
+
if (this._a < 1) {
|
|
520
|
+
return false;
|
|
521
|
+
}
|
|
522
|
+
return hexNames[rgbToHex(this._r, this._g, this._b, true)] || false;
|
|
523
|
+
},
|
|
524
|
+
toFilter: function toFilter(secondColor) {
|
|
525
|
+
var hex8String = "#" + rgbaToArgbHex(this._r, this._g, this._b, this._a);
|
|
526
|
+
var secondHex8String = hex8String;
|
|
527
|
+
var gradientType = this._gradientType ? "GradientType = 1, " : "";
|
|
528
|
+
if (secondColor) {
|
|
529
|
+
var s = tinycolor(secondColor);
|
|
530
|
+
secondHex8String = "#" + rgbaToArgbHex(s._r, s._g, s._b, s._a);
|
|
531
|
+
}
|
|
532
|
+
return "progid:DXImageTransform.Microsoft.gradient(" + gradientType + "startColorstr=" + hex8String + ",endColorstr=" + secondHex8String + ")";
|
|
533
|
+
},
|
|
534
|
+
toString: function toString(format) {
|
|
535
|
+
var formatSet = !!format;
|
|
536
|
+
format = format || this._format;
|
|
537
|
+
var formattedString = false;
|
|
538
|
+
var hasAlpha = this._a < 1 && this._a >= 0;
|
|
539
|
+
var needsAlphaFormat = !formatSet && hasAlpha && (format === "hex" || format === "hex6" || format === "hex3" || format === "hex4" || format === "hex8" || format === "name");
|
|
540
|
+
if (needsAlphaFormat) {
|
|
541
|
+
if (format === "name" && this._a === 0) {
|
|
542
|
+
return this.toName();
|
|
543
|
+
}
|
|
544
|
+
return this.toRgbString();
|
|
545
|
+
}
|
|
546
|
+
if (format === "rgb") {
|
|
547
|
+
formattedString = this.toRgbString();
|
|
548
|
+
}
|
|
549
|
+
if (format === "prgb") {
|
|
550
|
+
formattedString = this.toPercentageRgbString();
|
|
551
|
+
}
|
|
552
|
+
if (format === "hex" || format === "hex6") {
|
|
553
|
+
formattedString = this.toHexString();
|
|
554
|
+
}
|
|
555
|
+
if (format === "hex3") {
|
|
556
|
+
formattedString = this.toHexString(true);
|
|
557
|
+
}
|
|
558
|
+
if (format === "hex4") {
|
|
559
|
+
formattedString = this.toHex8String(true);
|
|
560
|
+
}
|
|
561
|
+
if (format === "hex8") {
|
|
562
|
+
formattedString = this.toHex8String();
|
|
563
|
+
}
|
|
564
|
+
if (format === "name") {
|
|
565
|
+
formattedString = this.toName();
|
|
566
|
+
}
|
|
567
|
+
if (format === "hsl") {
|
|
568
|
+
formattedString = this.toHslString();
|
|
569
|
+
}
|
|
570
|
+
if (format === "hsv") {
|
|
571
|
+
formattedString = this.toHsvString();
|
|
572
|
+
}
|
|
573
|
+
return formattedString || this.toHexString();
|
|
574
|
+
},
|
|
575
|
+
clone: function clone() {
|
|
576
|
+
return tinycolor(this.toString());
|
|
577
|
+
},
|
|
578
|
+
_applyModification: function _applyModification(fn, args) {
|
|
579
|
+
var color = fn.apply(null, [this].concat([].slice.call(args)));
|
|
580
|
+
this._r = color._r;
|
|
581
|
+
this._g = color._g;
|
|
582
|
+
this._b = color._b;
|
|
583
|
+
this.setAlpha(color._a);
|
|
584
|
+
return this;
|
|
585
|
+
},
|
|
586
|
+
lighten: function lighten() {
|
|
587
|
+
return this._applyModification(_lighten, arguments);
|
|
588
|
+
},
|
|
589
|
+
brighten: function brighten() {
|
|
590
|
+
return this._applyModification(_brighten, arguments);
|
|
591
|
+
},
|
|
592
|
+
darken: function darken() {
|
|
593
|
+
return this._applyModification(_darken, arguments);
|
|
594
|
+
},
|
|
595
|
+
desaturate: function desaturate() {
|
|
596
|
+
return this._applyModification(_desaturate, arguments);
|
|
597
|
+
},
|
|
598
|
+
saturate: function saturate() {
|
|
599
|
+
return this._applyModification(_saturate, arguments);
|
|
600
|
+
},
|
|
601
|
+
greyscale: function greyscale() {
|
|
602
|
+
return this._applyModification(_greyscale, arguments);
|
|
603
|
+
},
|
|
604
|
+
spin: function spin() {
|
|
605
|
+
return this._applyModification(_spin, arguments);
|
|
606
|
+
},
|
|
607
|
+
_applyCombination: function _applyCombination(fn, args) {
|
|
608
|
+
return fn.apply(null, [this].concat([].slice.call(args)));
|
|
609
|
+
},
|
|
610
|
+
analogous: function analogous() {
|
|
611
|
+
return this._applyCombination(_analogous, arguments);
|
|
612
|
+
},
|
|
613
|
+
complement: function complement() {
|
|
614
|
+
return this._applyCombination(_complement, arguments);
|
|
615
|
+
},
|
|
616
|
+
monochromatic: function monochromatic() {
|
|
617
|
+
return this._applyCombination(_monochromatic, arguments);
|
|
618
|
+
},
|
|
619
|
+
splitcomplement: function splitcomplement() {
|
|
620
|
+
return this._applyCombination(_splitcomplement, arguments);
|
|
621
|
+
},
|
|
622
|
+
// Disabled until https://github.com/bgrins/TinyColor/issues/254
|
|
623
|
+
// polyad: function (number) {
|
|
624
|
+
// return this._applyCombination(polyad, [number]);
|
|
625
|
+
// },
|
|
626
|
+
triad: function triad() {
|
|
627
|
+
return this._applyCombination(polyad, [3]);
|
|
628
|
+
},
|
|
629
|
+
tetrad: function tetrad() {
|
|
630
|
+
return this._applyCombination(polyad, [4]);
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
tinycolor.fromRatio = function(color, opts) {
|
|
634
|
+
if (_typeof(color) == "object") {
|
|
635
|
+
var newColor = {};
|
|
636
|
+
for (var i in color) {
|
|
637
|
+
if (color.hasOwnProperty(i)) {
|
|
638
|
+
if (i === "a") {
|
|
639
|
+
newColor[i] = color[i];
|
|
640
|
+
} else {
|
|
641
|
+
newColor[i] = convertToPercentage(color[i]);
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
color = newColor;
|
|
646
|
+
}
|
|
647
|
+
return tinycolor(color, opts);
|
|
648
|
+
};
|
|
649
|
+
function inputToRGB(color) {
|
|
650
|
+
var rgb = {
|
|
651
|
+
r: 0,
|
|
652
|
+
g: 0,
|
|
653
|
+
b: 0
|
|
654
|
+
};
|
|
655
|
+
var a = 1;
|
|
656
|
+
var s = null;
|
|
657
|
+
var v = null;
|
|
658
|
+
var l = null;
|
|
659
|
+
var ok = false;
|
|
660
|
+
var format = false;
|
|
661
|
+
if (typeof color == "string") {
|
|
662
|
+
color = stringInputToObject(color);
|
|
663
|
+
}
|
|
664
|
+
if (_typeof(color) == "object") {
|
|
665
|
+
if (isValidCSSUnit(color.r) && isValidCSSUnit(color.g) && isValidCSSUnit(color.b)) {
|
|
666
|
+
rgb = rgbToRgb(color.r, color.g, color.b);
|
|
667
|
+
ok = true;
|
|
668
|
+
format = String(color.r).substr(-1) === "%" ? "prgb" : "rgb";
|
|
669
|
+
} else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.v)) {
|
|
670
|
+
s = convertToPercentage(color.s);
|
|
671
|
+
v = convertToPercentage(color.v);
|
|
672
|
+
rgb = hsvToRgb(color.h, s, v);
|
|
673
|
+
ok = true;
|
|
674
|
+
format = "hsv";
|
|
675
|
+
} else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.l)) {
|
|
676
|
+
s = convertToPercentage(color.s);
|
|
677
|
+
l = convertToPercentage(color.l);
|
|
678
|
+
rgb = hslToRgb(color.h, s, l);
|
|
679
|
+
ok = true;
|
|
680
|
+
format = "hsl";
|
|
681
|
+
}
|
|
682
|
+
if (color.hasOwnProperty("a")) {
|
|
683
|
+
a = color.a;
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
a = boundAlpha(a);
|
|
687
|
+
return {
|
|
688
|
+
ok,
|
|
689
|
+
format: color.format || format,
|
|
690
|
+
r: Math.min(255, Math.max(rgb.r, 0)),
|
|
691
|
+
g: Math.min(255, Math.max(rgb.g, 0)),
|
|
692
|
+
b: Math.min(255, Math.max(rgb.b, 0)),
|
|
693
|
+
a
|
|
694
|
+
};
|
|
695
|
+
}
|
|
696
|
+
function rgbToRgb(r, g, b) {
|
|
697
|
+
return {
|
|
698
|
+
r: bound01(r, 255) * 255,
|
|
699
|
+
g: bound01(g, 255) * 255,
|
|
700
|
+
b: bound01(b, 255) * 255
|
|
701
|
+
};
|
|
702
|
+
}
|
|
703
|
+
function rgbToHsl(r, g, b) {
|
|
704
|
+
r = bound01(r, 255);
|
|
705
|
+
g = bound01(g, 255);
|
|
706
|
+
b = bound01(b, 255);
|
|
707
|
+
var max = Math.max(r, g, b), min = Math.min(r, g, b);
|
|
708
|
+
var h, s, l = (max + min) / 2;
|
|
709
|
+
if (max == min) {
|
|
710
|
+
h = s = 0;
|
|
711
|
+
} else {
|
|
712
|
+
var d = max - min;
|
|
713
|
+
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
714
|
+
switch (max) {
|
|
715
|
+
case r:
|
|
716
|
+
h = (g - b) / d + (g < b ? 6 : 0);
|
|
717
|
+
break;
|
|
718
|
+
case g:
|
|
719
|
+
h = (b - r) / d + 2;
|
|
720
|
+
break;
|
|
721
|
+
case b:
|
|
722
|
+
h = (r - g) / d + 4;
|
|
723
|
+
break;
|
|
724
|
+
}
|
|
725
|
+
h /= 6;
|
|
726
|
+
}
|
|
727
|
+
return {
|
|
728
|
+
h,
|
|
729
|
+
s,
|
|
730
|
+
l
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
function hslToRgb(h, s, l) {
|
|
734
|
+
var r, g, b;
|
|
735
|
+
h = bound01(h, 360);
|
|
736
|
+
s = bound01(s, 100);
|
|
737
|
+
l = bound01(l, 100);
|
|
738
|
+
function hue2rgb(p2, q2, t) {
|
|
739
|
+
if (t < 0)
|
|
740
|
+
t += 1;
|
|
741
|
+
if (t > 1)
|
|
742
|
+
t -= 1;
|
|
743
|
+
if (t < 1 / 6)
|
|
744
|
+
return p2 + (q2 - p2) * 6 * t;
|
|
745
|
+
if (t < 1 / 2)
|
|
746
|
+
return q2;
|
|
747
|
+
if (t < 2 / 3)
|
|
748
|
+
return p2 + (q2 - p2) * (2 / 3 - t) * 6;
|
|
749
|
+
return p2;
|
|
750
|
+
}
|
|
751
|
+
if (s === 0) {
|
|
752
|
+
r = g = b = l;
|
|
753
|
+
} else {
|
|
754
|
+
var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
|
755
|
+
var p = 2 * l - q;
|
|
756
|
+
r = hue2rgb(p, q, h + 1 / 3);
|
|
757
|
+
g = hue2rgb(p, q, h);
|
|
758
|
+
b = hue2rgb(p, q, h - 1 / 3);
|
|
759
|
+
}
|
|
760
|
+
return {
|
|
761
|
+
r: r * 255,
|
|
762
|
+
g: g * 255,
|
|
763
|
+
b: b * 255
|
|
764
|
+
};
|
|
765
|
+
}
|
|
766
|
+
function rgbToHsv(r, g, b) {
|
|
767
|
+
r = bound01(r, 255);
|
|
768
|
+
g = bound01(g, 255);
|
|
769
|
+
b = bound01(b, 255);
|
|
770
|
+
var max = Math.max(r, g, b), min = Math.min(r, g, b);
|
|
771
|
+
var h, s, v = max;
|
|
772
|
+
var d = max - min;
|
|
773
|
+
s = max === 0 ? 0 : d / max;
|
|
774
|
+
if (max == min) {
|
|
775
|
+
h = 0;
|
|
776
|
+
} else {
|
|
777
|
+
switch (max) {
|
|
778
|
+
case r:
|
|
779
|
+
h = (g - b) / d + (g < b ? 6 : 0);
|
|
780
|
+
break;
|
|
781
|
+
case g:
|
|
782
|
+
h = (b - r) / d + 2;
|
|
783
|
+
break;
|
|
784
|
+
case b:
|
|
785
|
+
h = (r - g) / d + 4;
|
|
786
|
+
break;
|
|
787
|
+
}
|
|
788
|
+
h /= 6;
|
|
789
|
+
}
|
|
790
|
+
return {
|
|
791
|
+
h,
|
|
792
|
+
s,
|
|
793
|
+
v
|
|
794
|
+
};
|
|
795
|
+
}
|
|
796
|
+
function hsvToRgb(h, s, v) {
|
|
797
|
+
h = bound01(h, 360) * 6;
|
|
798
|
+
s = bound01(s, 100);
|
|
799
|
+
v = bound01(v, 100);
|
|
800
|
+
var i = Math.floor(h), f = h - i, p = v * (1 - s), q = v * (1 - f * s), t = v * (1 - (1 - f) * s), mod = i % 6, r = [v, q, p, p, t, v][mod], g = [t, v, v, q, p, p][mod], b = [p, p, t, v, v, q][mod];
|
|
801
|
+
return {
|
|
802
|
+
r: r * 255,
|
|
803
|
+
g: g * 255,
|
|
804
|
+
b: b * 255
|
|
805
|
+
};
|
|
806
|
+
}
|
|
807
|
+
function rgbToHex(r, g, b, allow3Char) {
|
|
808
|
+
var hex = [pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16))];
|
|
809
|
+
if (allow3Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1)) {
|
|
810
|
+
return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0);
|
|
811
|
+
}
|
|
812
|
+
return hex.join("");
|
|
813
|
+
}
|
|
814
|
+
function rgbaToHex(r, g, b, a, allow4Char) {
|
|
815
|
+
var hex = [pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16)), pad2(convertDecimalToHex(a))];
|
|
816
|
+
if (allow4Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1) && hex[3].charAt(0) == hex[3].charAt(1)) {
|
|
817
|
+
return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0) + hex[3].charAt(0);
|
|
818
|
+
}
|
|
819
|
+
return hex.join("");
|
|
820
|
+
}
|
|
821
|
+
function rgbaToArgbHex(r, g, b, a) {
|
|
822
|
+
var hex = [pad2(convertDecimalToHex(a)), pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16))];
|
|
823
|
+
return hex.join("");
|
|
824
|
+
}
|
|
825
|
+
tinycolor.equals = function(color1, color2) {
|
|
826
|
+
if (!color1 || !color2)
|
|
827
|
+
return false;
|
|
828
|
+
return tinycolor(color1).toRgbString() == tinycolor(color2).toRgbString();
|
|
829
|
+
};
|
|
830
|
+
tinycolor.random = function() {
|
|
831
|
+
return tinycolor.fromRatio({
|
|
832
|
+
r: Math.random(),
|
|
833
|
+
g: Math.random(),
|
|
834
|
+
b: Math.random()
|
|
835
|
+
});
|
|
529
836
|
};
|
|
837
|
+
function _desaturate(color, amount) {
|
|
838
|
+
amount = amount === 0 ? 0 : amount || 10;
|
|
839
|
+
var hsl = tinycolor(color).toHsl();
|
|
840
|
+
hsl.s -= amount / 100;
|
|
841
|
+
hsl.s = clamp01(hsl.s);
|
|
842
|
+
return tinycolor(hsl);
|
|
843
|
+
}
|
|
844
|
+
function _saturate(color, amount) {
|
|
845
|
+
amount = amount === 0 ? 0 : amount || 10;
|
|
846
|
+
var hsl = tinycolor(color).toHsl();
|
|
847
|
+
hsl.s += amount / 100;
|
|
848
|
+
hsl.s = clamp01(hsl.s);
|
|
849
|
+
return tinycolor(hsl);
|
|
850
|
+
}
|
|
851
|
+
function _greyscale(color) {
|
|
852
|
+
return tinycolor(color).desaturate(100);
|
|
853
|
+
}
|
|
854
|
+
function _lighten(color, amount) {
|
|
855
|
+
amount = amount === 0 ? 0 : amount || 10;
|
|
856
|
+
var hsl = tinycolor(color).toHsl();
|
|
857
|
+
hsl.l += amount / 100;
|
|
858
|
+
hsl.l = clamp01(hsl.l);
|
|
859
|
+
return tinycolor(hsl);
|
|
860
|
+
}
|
|
861
|
+
function _brighten(color, amount) {
|
|
862
|
+
amount = amount === 0 ? 0 : amount || 10;
|
|
863
|
+
var rgb = tinycolor(color).toRgb();
|
|
864
|
+
rgb.r = Math.max(0, Math.min(255, rgb.r - Math.round(255 * -(amount / 100))));
|
|
865
|
+
rgb.g = Math.max(0, Math.min(255, rgb.g - Math.round(255 * -(amount / 100))));
|
|
866
|
+
rgb.b = Math.max(0, Math.min(255, rgb.b - Math.round(255 * -(amount / 100))));
|
|
867
|
+
return tinycolor(rgb);
|
|
868
|
+
}
|
|
869
|
+
function _darken(color, amount) {
|
|
870
|
+
amount = amount === 0 ? 0 : amount || 10;
|
|
871
|
+
var hsl = tinycolor(color).toHsl();
|
|
872
|
+
hsl.l -= amount / 100;
|
|
873
|
+
hsl.l = clamp01(hsl.l);
|
|
874
|
+
return tinycolor(hsl);
|
|
875
|
+
}
|
|
876
|
+
function _spin(color, amount) {
|
|
877
|
+
var hsl = tinycolor(color).toHsl();
|
|
878
|
+
var hue = (hsl.h + amount) % 360;
|
|
879
|
+
hsl.h = hue < 0 ? 360 + hue : hue;
|
|
880
|
+
return tinycolor(hsl);
|
|
881
|
+
}
|
|
882
|
+
function _complement(color) {
|
|
883
|
+
var hsl = tinycolor(color).toHsl();
|
|
884
|
+
hsl.h = (hsl.h + 180) % 360;
|
|
885
|
+
return tinycolor(hsl);
|
|
886
|
+
}
|
|
887
|
+
function polyad(color, number) {
|
|
888
|
+
if (isNaN(number) || number <= 0) {
|
|
889
|
+
throw new Error("Argument to polyad must be a positive number");
|
|
890
|
+
}
|
|
891
|
+
var hsl = tinycolor(color).toHsl();
|
|
892
|
+
var result = [tinycolor(color)];
|
|
893
|
+
var step = 360 / number;
|
|
894
|
+
for (var i = 1; i < number; i++) {
|
|
895
|
+
result.push(tinycolor({
|
|
896
|
+
h: (hsl.h + i * step) % 360,
|
|
897
|
+
s: hsl.s,
|
|
898
|
+
l: hsl.l
|
|
899
|
+
}));
|
|
900
|
+
}
|
|
901
|
+
return result;
|
|
902
|
+
}
|
|
903
|
+
function _splitcomplement(color) {
|
|
904
|
+
var hsl = tinycolor(color).toHsl();
|
|
905
|
+
var h = hsl.h;
|
|
906
|
+
return [tinycolor(color), tinycolor({
|
|
907
|
+
h: (h + 72) % 360,
|
|
908
|
+
s: hsl.s,
|
|
909
|
+
l: hsl.l
|
|
910
|
+
}), tinycolor({
|
|
911
|
+
h: (h + 216) % 360,
|
|
912
|
+
s: hsl.s,
|
|
913
|
+
l: hsl.l
|
|
914
|
+
})];
|
|
915
|
+
}
|
|
916
|
+
function _analogous(color, results, slices) {
|
|
917
|
+
results = results || 6;
|
|
918
|
+
slices = slices || 30;
|
|
919
|
+
var hsl = tinycolor(color).toHsl();
|
|
920
|
+
var part = 360 / slices;
|
|
921
|
+
var ret = [tinycolor(color)];
|
|
922
|
+
for (hsl.h = (hsl.h - (part * results >> 1) + 720) % 360; --results; ) {
|
|
923
|
+
hsl.h = (hsl.h + part) % 360;
|
|
924
|
+
ret.push(tinycolor(hsl));
|
|
925
|
+
}
|
|
926
|
+
return ret;
|
|
927
|
+
}
|
|
928
|
+
function _monochromatic(color, results) {
|
|
929
|
+
results = results || 6;
|
|
930
|
+
var hsv = tinycolor(color).toHsv();
|
|
931
|
+
var h = hsv.h, s = hsv.s, v = hsv.v;
|
|
932
|
+
var ret = [];
|
|
933
|
+
var modification = 1 / results;
|
|
934
|
+
while (results--) {
|
|
935
|
+
ret.push(tinycolor({
|
|
936
|
+
h,
|
|
937
|
+
s,
|
|
938
|
+
v
|
|
939
|
+
}));
|
|
940
|
+
v = (v + modification) % 1;
|
|
941
|
+
}
|
|
942
|
+
return ret;
|
|
943
|
+
}
|
|
944
|
+
tinycolor.mix = function(color1, color2, amount) {
|
|
945
|
+
amount = amount === 0 ? 0 : amount || 50;
|
|
946
|
+
var rgb1 = tinycolor(color1).toRgb();
|
|
947
|
+
var rgb2 = tinycolor(color2).toRgb();
|
|
948
|
+
var p = amount / 100;
|
|
949
|
+
var rgba = {
|
|
950
|
+
r: (rgb2.r - rgb1.r) * p + rgb1.r,
|
|
951
|
+
g: (rgb2.g - rgb1.g) * p + rgb1.g,
|
|
952
|
+
b: (rgb2.b - rgb1.b) * p + rgb1.b,
|
|
953
|
+
a: (rgb2.a - rgb1.a) * p + rgb1.a
|
|
954
|
+
};
|
|
955
|
+
return tinycolor(rgba);
|
|
956
|
+
};
|
|
957
|
+
tinycolor.readability = function(color1, color2) {
|
|
958
|
+
var c1 = tinycolor(color1);
|
|
959
|
+
var c2 = tinycolor(color2);
|
|
960
|
+
return (Math.max(c1.getLuminance(), c2.getLuminance()) + 0.05) / (Math.min(c1.getLuminance(), c2.getLuminance()) + 0.05);
|
|
961
|
+
};
|
|
962
|
+
tinycolor.isReadable = function(color1, color2, wcag2) {
|
|
963
|
+
var readability = tinycolor.readability(color1, color2);
|
|
964
|
+
var wcag2Parms, out;
|
|
965
|
+
out = false;
|
|
966
|
+
wcag2Parms = validateWCAG2Parms(wcag2);
|
|
967
|
+
switch (wcag2Parms.level + wcag2Parms.size) {
|
|
968
|
+
case "AAsmall":
|
|
969
|
+
case "AAAlarge":
|
|
970
|
+
out = readability >= 4.5;
|
|
971
|
+
break;
|
|
972
|
+
case "AAlarge":
|
|
973
|
+
out = readability >= 3;
|
|
974
|
+
break;
|
|
975
|
+
case "AAAsmall":
|
|
976
|
+
out = readability >= 7;
|
|
977
|
+
break;
|
|
978
|
+
}
|
|
979
|
+
return out;
|
|
980
|
+
};
|
|
981
|
+
tinycolor.mostReadable = function(baseColor, colorList, args) {
|
|
982
|
+
var bestColor = null;
|
|
983
|
+
var bestScore = 0;
|
|
984
|
+
var readability;
|
|
985
|
+
var includeFallbackColors, level, size;
|
|
986
|
+
args = args || {};
|
|
987
|
+
includeFallbackColors = args.includeFallbackColors;
|
|
988
|
+
level = args.level;
|
|
989
|
+
size = args.size;
|
|
990
|
+
for (var i = 0; i < colorList.length; i++) {
|
|
991
|
+
readability = tinycolor.readability(baseColor, colorList[i]);
|
|
992
|
+
if (readability > bestScore) {
|
|
993
|
+
bestScore = readability;
|
|
994
|
+
bestColor = tinycolor(colorList[i]);
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
if (tinycolor.isReadable(baseColor, bestColor, {
|
|
998
|
+
level,
|
|
999
|
+
size
|
|
1000
|
+
}) || !includeFallbackColors) {
|
|
1001
|
+
return bestColor;
|
|
1002
|
+
} else {
|
|
1003
|
+
args.includeFallbackColors = false;
|
|
1004
|
+
return tinycolor.mostReadable(baseColor, ["#fff", "#000"], args);
|
|
1005
|
+
}
|
|
1006
|
+
};
|
|
1007
|
+
var names = tinycolor.names = {
|
|
1008
|
+
aliceblue: "f0f8ff",
|
|
1009
|
+
antiquewhite: "faebd7",
|
|
1010
|
+
aqua: "0ff",
|
|
1011
|
+
aquamarine: "7fffd4",
|
|
1012
|
+
azure: "f0ffff",
|
|
1013
|
+
beige: "f5f5dc",
|
|
1014
|
+
bisque: "ffe4c4",
|
|
1015
|
+
black: "000",
|
|
1016
|
+
blanchedalmond: "ffebcd",
|
|
1017
|
+
blue: "00f",
|
|
1018
|
+
blueviolet: "8a2be2",
|
|
1019
|
+
brown: "a52a2a",
|
|
1020
|
+
burlywood: "deb887",
|
|
1021
|
+
burntsienna: "ea7e5d",
|
|
1022
|
+
cadetblue: "5f9ea0",
|
|
1023
|
+
chartreuse: "7fff00",
|
|
1024
|
+
chocolate: "d2691e",
|
|
1025
|
+
coral: "ff7f50",
|
|
1026
|
+
cornflowerblue: "6495ed",
|
|
1027
|
+
cornsilk: "fff8dc",
|
|
1028
|
+
crimson: "dc143c",
|
|
1029
|
+
cyan: "0ff",
|
|
1030
|
+
darkblue: "00008b",
|
|
1031
|
+
darkcyan: "008b8b",
|
|
1032
|
+
darkgoldenrod: "b8860b",
|
|
1033
|
+
darkgray: "a9a9a9",
|
|
1034
|
+
darkgreen: "006400",
|
|
1035
|
+
darkgrey: "a9a9a9",
|
|
1036
|
+
darkkhaki: "bdb76b",
|
|
1037
|
+
darkmagenta: "8b008b",
|
|
1038
|
+
darkolivegreen: "556b2f",
|
|
1039
|
+
darkorange: "ff8c00",
|
|
1040
|
+
darkorchid: "9932cc",
|
|
1041
|
+
darkred: "8b0000",
|
|
1042
|
+
darksalmon: "e9967a",
|
|
1043
|
+
darkseagreen: "8fbc8f",
|
|
1044
|
+
darkslateblue: "483d8b",
|
|
1045
|
+
darkslategray: "2f4f4f",
|
|
1046
|
+
darkslategrey: "2f4f4f",
|
|
1047
|
+
darkturquoise: "00ced1",
|
|
1048
|
+
darkviolet: "9400d3",
|
|
1049
|
+
deeppink: "ff1493",
|
|
1050
|
+
deepskyblue: "00bfff",
|
|
1051
|
+
dimgray: "696969",
|
|
1052
|
+
dimgrey: "696969",
|
|
1053
|
+
dodgerblue: "1e90ff",
|
|
1054
|
+
firebrick: "b22222",
|
|
1055
|
+
floralwhite: "fffaf0",
|
|
1056
|
+
forestgreen: "228b22",
|
|
1057
|
+
fuchsia: "f0f",
|
|
1058
|
+
gainsboro: "dcdcdc",
|
|
1059
|
+
ghostwhite: "f8f8ff",
|
|
1060
|
+
gold: "ffd700",
|
|
1061
|
+
goldenrod: "daa520",
|
|
1062
|
+
gray: "808080",
|
|
1063
|
+
green: "008000",
|
|
1064
|
+
greenyellow: "adff2f",
|
|
1065
|
+
grey: "808080",
|
|
1066
|
+
honeydew: "f0fff0",
|
|
1067
|
+
hotpink: "ff69b4",
|
|
1068
|
+
indianred: "cd5c5c",
|
|
1069
|
+
indigo: "4b0082",
|
|
1070
|
+
ivory: "fffff0",
|
|
1071
|
+
khaki: "f0e68c",
|
|
1072
|
+
lavender: "e6e6fa",
|
|
1073
|
+
lavenderblush: "fff0f5",
|
|
1074
|
+
lawngreen: "7cfc00",
|
|
1075
|
+
lemonchiffon: "fffacd",
|
|
1076
|
+
lightblue: "add8e6",
|
|
1077
|
+
lightcoral: "f08080",
|
|
1078
|
+
lightcyan: "e0ffff",
|
|
1079
|
+
lightgoldenrodyellow: "fafad2",
|
|
1080
|
+
lightgray: "d3d3d3",
|
|
1081
|
+
lightgreen: "90ee90",
|
|
1082
|
+
lightgrey: "d3d3d3",
|
|
1083
|
+
lightpink: "ffb6c1",
|
|
1084
|
+
lightsalmon: "ffa07a",
|
|
1085
|
+
lightseagreen: "20b2aa",
|
|
1086
|
+
lightskyblue: "87cefa",
|
|
1087
|
+
lightslategray: "789",
|
|
1088
|
+
lightslategrey: "789",
|
|
1089
|
+
lightsteelblue: "b0c4de",
|
|
1090
|
+
lightyellow: "ffffe0",
|
|
1091
|
+
lime: "0f0",
|
|
1092
|
+
limegreen: "32cd32",
|
|
1093
|
+
linen: "faf0e6",
|
|
1094
|
+
magenta: "f0f",
|
|
1095
|
+
maroon: "800000",
|
|
1096
|
+
mediumaquamarine: "66cdaa",
|
|
1097
|
+
mediumblue: "0000cd",
|
|
1098
|
+
mediumorchid: "ba55d3",
|
|
1099
|
+
mediumpurple: "9370db",
|
|
1100
|
+
mediumseagreen: "3cb371",
|
|
1101
|
+
mediumslateblue: "7b68ee",
|
|
1102
|
+
mediumspringgreen: "00fa9a",
|
|
1103
|
+
mediumturquoise: "48d1cc",
|
|
1104
|
+
mediumvioletred: "c71585",
|
|
1105
|
+
midnightblue: "191970",
|
|
1106
|
+
mintcream: "f5fffa",
|
|
1107
|
+
mistyrose: "ffe4e1",
|
|
1108
|
+
moccasin: "ffe4b5",
|
|
1109
|
+
navajowhite: "ffdead",
|
|
1110
|
+
navy: "000080",
|
|
1111
|
+
oldlace: "fdf5e6",
|
|
1112
|
+
olive: "808000",
|
|
1113
|
+
olivedrab: "6b8e23",
|
|
1114
|
+
orange: "ffa500",
|
|
1115
|
+
orangered: "ff4500",
|
|
1116
|
+
orchid: "da70d6",
|
|
1117
|
+
palegoldenrod: "eee8aa",
|
|
1118
|
+
palegreen: "98fb98",
|
|
1119
|
+
paleturquoise: "afeeee",
|
|
1120
|
+
palevioletred: "db7093",
|
|
1121
|
+
papayawhip: "ffefd5",
|
|
1122
|
+
peachpuff: "ffdab9",
|
|
1123
|
+
peru: "cd853f",
|
|
1124
|
+
pink: "ffc0cb",
|
|
1125
|
+
plum: "dda0dd",
|
|
1126
|
+
powderblue: "b0e0e6",
|
|
1127
|
+
purple: "800080",
|
|
1128
|
+
rebeccapurple: "663399",
|
|
1129
|
+
red: "f00",
|
|
1130
|
+
rosybrown: "bc8f8f",
|
|
1131
|
+
royalblue: "4169e1",
|
|
1132
|
+
saddlebrown: "8b4513",
|
|
1133
|
+
salmon: "fa8072",
|
|
1134
|
+
sandybrown: "f4a460",
|
|
1135
|
+
seagreen: "2e8b57",
|
|
1136
|
+
seashell: "fff5ee",
|
|
1137
|
+
sienna: "a0522d",
|
|
1138
|
+
silver: "c0c0c0",
|
|
1139
|
+
skyblue: "87ceeb",
|
|
1140
|
+
slateblue: "6a5acd",
|
|
1141
|
+
slategray: "708090",
|
|
1142
|
+
slategrey: "708090",
|
|
1143
|
+
snow: "fffafa",
|
|
1144
|
+
springgreen: "00ff7f",
|
|
1145
|
+
steelblue: "4682b4",
|
|
1146
|
+
tan: "d2b48c",
|
|
1147
|
+
teal: "008080",
|
|
1148
|
+
thistle: "d8bfd8",
|
|
1149
|
+
tomato: "ff6347",
|
|
1150
|
+
turquoise: "40e0d0",
|
|
1151
|
+
violet: "ee82ee",
|
|
1152
|
+
wheat: "f5deb3",
|
|
1153
|
+
white: "fff",
|
|
1154
|
+
whitesmoke: "f5f5f5",
|
|
1155
|
+
yellow: "ff0",
|
|
1156
|
+
yellowgreen: "9acd32"
|
|
1157
|
+
};
|
|
1158
|
+
var hexNames = tinycolor.hexNames = flip(names);
|
|
1159
|
+
function flip(o) {
|
|
1160
|
+
var flipped = {};
|
|
1161
|
+
for (var i in o) {
|
|
1162
|
+
if (o.hasOwnProperty(i)) {
|
|
1163
|
+
flipped[o[i]] = i;
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
return flipped;
|
|
1167
|
+
}
|
|
1168
|
+
function boundAlpha(a) {
|
|
1169
|
+
a = parseFloat(a);
|
|
1170
|
+
if (isNaN(a) || a < 0 || a > 1) {
|
|
1171
|
+
a = 1;
|
|
1172
|
+
}
|
|
1173
|
+
return a;
|
|
1174
|
+
}
|
|
1175
|
+
function bound01(n, max) {
|
|
1176
|
+
if (isOnePointZero(n))
|
|
1177
|
+
n = "100%";
|
|
1178
|
+
var processPercent = isPercentage(n);
|
|
1179
|
+
n = Math.min(max, Math.max(0, parseFloat(n)));
|
|
1180
|
+
if (processPercent) {
|
|
1181
|
+
n = parseInt(n * max, 10) / 100;
|
|
1182
|
+
}
|
|
1183
|
+
if (Math.abs(n - max) < 1e-6) {
|
|
1184
|
+
return 1;
|
|
1185
|
+
}
|
|
1186
|
+
return n % max / parseFloat(max);
|
|
1187
|
+
}
|
|
1188
|
+
function clamp01(val) {
|
|
1189
|
+
return Math.min(1, Math.max(0, val));
|
|
1190
|
+
}
|
|
1191
|
+
function parseIntFromHex(val) {
|
|
1192
|
+
return parseInt(val, 16);
|
|
1193
|
+
}
|
|
1194
|
+
function isOnePointZero(n) {
|
|
1195
|
+
return typeof n == "string" && n.indexOf(".") != -1 && parseFloat(n) === 1;
|
|
1196
|
+
}
|
|
1197
|
+
function isPercentage(n) {
|
|
1198
|
+
return typeof n === "string" && n.indexOf("%") != -1;
|
|
1199
|
+
}
|
|
1200
|
+
function pad2(c) {
|
|
1201
|
+
return c.length == 1 ? "0" + c : "" + c;
|
|
1202
|
+
}
|
|
1203
|
+
function convertToPercentage(n) {
|
|
1204
|
+
if (n <= 1) {
|
|
1205
|
+
n = n * 100 + "%";
|
|
1206
|
+
}
|
|
1207
|
+
return n;
|
|
1208
|
+
}
|
|
1209
|
+
function convertDecimalToHex(d) {
|
|
1210
|
+
return Math.round(parseFloat(d) * 255).toString(16);
|
|
1211
|
+
}
|
|
1212
|
+
function convertHexToDecimal(h) {
|
|
1213
|
+
return parseIntFromHex(h) / 255;
|
|
1214
|
+
}
|
|
1215
|
+
var matchers = function() {
|
|
1216
|
+
var CSS_INTEGER = "[-\\+]?\\d+%?";
|
|
1217
|
+
var CSS_NUMBER = "[-\\+]?\\d*\\.\\d+%?";
|
|
1218
|
+
var CSS_UNIT = "(?:" + CSS_NUMBER + ")|(?:" + CSS_INTEGER + ")";
|
|
1219
|
+
var PERMISSIVE_MATCH3 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
|
|
1220
|
+
var PERMISSIVE_MATCH4 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
|
|
1221
|
+
return {
|
|
1222
|
+
CSS_UNIT: new RegExp(CSS_UNIT),
|
|
1223
|
+
rgb: new RegExp("rgb" + PERMISSIVE_MATCH3),
|
|
1224
|
+
rgba: new RegExp("rgba" + PERMISSIVE_MATCH4),
|
|
1225
|
+
hsl: new RegExp("hsl" + PERMISSIVE_MATCH3),
|
|
1226
|
+
hsla: new RegExp("hsla" + PERMISSIVE_MATCH4),
|
|
1227
|
+
hsv: new RegExp("hsv" + PERMISSIVE_MATCH3),
|
|
1228
|
+
hsva: new RegExp("hsva" + PERMISSIVE_MATCH4),
|
|
1229
|
+
hex3: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
|
|
1230
|
+
hex6: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
|
|
1231
|
+
hex4: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
|
|
1232
|
+
hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/
|
|
1233
|
+
};
|
|
1234
|
+
}();
|
|
1235
|
+
function isValidCSSUnit(color) {
|
|
1236
|
+
return !!matchers.CSS_UNIT.exec(color);
|
|
1237
|
+
}
|
|
1238
|
+
function stringInputToObject(color) {
|
|
1239
|
+
color = color.replace(trimLeft, "").replace(trimRight, "").toLowerCase();
|
|
1240
|
+
var named = false;
|
|
1241
|
+
if (names[color]) {
|
|
1242
|
+
color = names[color];
|
|
1243
|
+
named = true;
|
|
1244
|
+
} else if (color == "transparent") {
|
|
1245
|
+
return {
|
|
1246
|
+
r: 0,
|
|
1247
|
+
g: 0,
|
|
1248
|
+
b: 0,
|
|
1249
|
+
a: 0,
|
|
1250
|
+
format: "name"
|
|
1251
|
+
};
|
|
1252
|
+
}
|
|
1253
|
+
var match;
|
|
1254
|
+
if (match = matchers.rgb.exec(color)) {
|
|
1255
|
+
return {
|
|
1256
|
+
r: match[1],
|
|
1257
|
+
g: match[2],
|
|
1258
|
+
b: match[3]
|
|
1259
|
+
};
|
|
1260
|
+
}
|
|
1261
|
+
if (match = matchers.rgba.exec(color)) {
|
|
1262
|
+
return {
|
|
1263
|
+
r: match[1],
|
|
1264
|
+
g: match[2],
|
|
1265
|
+
b: match[3],
|
|
1266
|
+
a: match[4]
|
|
1267
|
+
};
|
|
1268
|
+
}
|
|
1269
|
+
if (match = matchers.hsl.exec(color)) {
|
|
1270
|
+
return {
|
|
1271
|
+
h: match[1],
|
|
1272
|
+
s: match[2],
|
|
1273
|
+
l: match[3]
|
|
1274
|
+
};
|
|
1275
|
+
}
|
|
1276
|
+
if (match = matchers.hsla.exec(color)) {
|
|
1277
|
+
return {
|
|
1278
|
+
h: match[1],
|
|
1279
|
+
s: match[2],
|
|
1280
|
+
l: match[3],
|
|
1281
|
+
a: match[4]
|
|
1282
|
+
};
|
|
1283
|
+
}
|
|
1284
|
+
if (match = matchers.hsv.exec(color)) {
|
|
1285
|
+
return {
|
|
1286
|
+
h: match[1],
|
|
1287
|
+
s: match[2],
|
|
1288
|
+
v: match[3]
|
|
1289
|
+
};
|
|
1290
|
+
}
|
|
1291
|
+
if (match = matchers.hsva.exec(color)) {
|
|
1292
|
+
return {
|
|
1293
|
+
h: match[1],
|
|
1294
|
+
s: match[2],
|
|
1295
|
+
v: match[3],
|
|
1296
|
+
a: match[4]
|
|
1297
|
+
};
|
|
1298
|
+
}
|
|
1299
|
+
if (match = matchers.hex8.exec(color)) {
|
|
1300
|
+
return {
|
|
1301
|
+
r: parseIntFromHex(match[1]),
|
|
1302
|
+
g: parseIntFromHex(match[2]),
|
|
1303
|
+
b: parseIntFromHex(match[3]),
|
|
1304
|
+
a: convertHexToDecimal(match[4]),
|
|
1305
|
+
format: named ? "name" : "hex8"
|
|
1306
|
+
};
|
|
1307
|
+
}
|
|
1308
|
+
if (match = matchers.hex6.exec(color)) {
|
|
1309
|
+
return {
|
|
1310
|
+
r: parseIntFromHex(match[1]),
|
|
1311
|
+
g: parseIntFromHex(match[2]),
|
|
1312
|
+
b: parseIntFromHex(match[3]),
|
|
1313
|
+
format: named ? "name" : "hex"
|
|
1314
|
+
};
|
|
1315
|
+
}
|
|
1316
|
+
if (match = matchers.hex4.exec(color)) {
|
|
1317
|
+
return {
|
|
1318
|
+
r: parseIntFromHex(match[1] + "" + match[1]),
|
|
1319
|
+
g: parseIntFromHex(match[2] + "" + match[2]),
|
|
1320
|
+
b: parseIntFromHex(match[3] + "" + match[3]),
|
|
1321
|
+
a: convertHexToDecimal(match[4] + "" + match[4]),
|
|
1322
|
+
format: named ? "name" : "hex8"
|
|
1323
|
+
};
|
|
1324
|
+
}
|
|
1325
|
+
if (match = matchers.hex3.exec(color)) {
|
|
1326
|
+
return {
|
|
1327
|
+
r: parseIntFromHex(match[1] + "" + match[1]),
|
|
1328
|
+
g: parseIntFromHex(match[2] + "" + match[2]),
|
|
1329
|
+
b: parseIntFromHex(match[3] + "" + match[3]),
|
|
1330
|
+
format: named ? "name" : "hex"
|
|
1331
|
+
};
|
|
1332
|
+
}
|
|
1333
|
+
return false;
|
|
1334
|
+
}
|
|
1335
|
+
function validateWCAG2Parms(parms) {
|
|
1336
|
+
var level, size;
|
|
1337
|
+
parms = parms || {
|
|
1338
|
+
level: "AA",
|
|
1339
|
+
size: "small"
|
|
1340
|
+
};
|
|
1341
|
+
level = (parms.level || "AA").toUpperCase();
|
|
1342
|
+
size = (parms.size || "small").toLowerCase();
|
|
1343
|
+
if (level !== "AA" && level !== "AAA") {
|
|
1344
|
+
level = "AA";
|
|
1345
|
+
}
|
|
1346
|
+
if (size !== "small" && size !== "large") {
|
|
1347
|
+
size = "small";
|
|
1348
|
+
}
|
|
1349
|
+
return {
|
|
1350
|
+
level,
|
|
1351
|
+
size
|
|
1352
|
+
};
|
|
1353
|
+
}
|
|
530
1354
|
|
|
531
1355
|
// src/colors.ts
|
|
532
|
-
|
|
1356
|
+
import { clamp } from "@excalidraw/math";
|
|
1357
|
+
import { degreesToRadians } from "@excalidraw/math";
|
|
1358
|
+
var DARK_MODE_COLORS_CACHE = typeof window !== "undefined" ? /* @__PURE__ */ new Map() : null;
|
|
1359
|
+
function cssHueRotate(red, green, blue, degrees) {
|
|
1360
|
+
const r = red / 255;
|
|
1361
|
+
const g = green / 255;
|
|
1362
|
+
const b = blue / 255;
|
|
1363
|
+
const a = degreesToRadians(degrees);
|
|
1364
|
+
const c = Math.cos(a);
|
|
1365
|
+
const s = Math.sin(a);
|
|
1366
|
+
const matrix = [
|
|
1367
|
+
0.213 + c * 0.787 - s * 0.213,
|
|
1368
|
+
0.715 - c * 0.715 - s * 0.715,
|
|
1369
|
+
0.072 - c * 0.072 + s * 0.928,
|
|
1370
|
+
0.213 - c * 0.213 + s * 0.143,
|
|
1371
|
+
0.715 + c * 0.285 + s * 0.14,
|
|
1372
|
+
0.072 - c * 0.072 - s * 0.283,
|
|
1373
|
+
0.213 - c * 0.213 - s * 0.787,
|
|
1374
|
+
0.715 - c * 0.715 + s * 0.715,
|
|
1375
|
+
0.072 + c * 0.928 + s * 0.072
|
|
1376
|
+
];
|
|
1377
|
+
const newR = r * matrix[0] + g * matrix[1] + b * matrix[2];
|
|
1378
|
+
const newG = r * matrix[3] + g * matrix[4] + b * matrix[5];
|
|
1379
|
+
const newB = r * matrix[6] + g * matrix[7] + b * matrix[8];
|
|
1380
|
+
return {
|
|
1381
|
+
r: Math.round(Math.max(0, Math.min(1, newR)) * 255),
|
|
1382
|
+
g: Math.round(Math.max(0, Math.min(1, newG)) * 255),
|
|
1383
|
+
b: Math.round(Math.max(0, Math.min(1, newB)) * 255)
|
|
1384
|
+
};
|
|
1385
|
+
}
|
|
1386
|
+
var cssInvert = (r, g, b, percent) => {
|
|
1387
|
+
const p = clamp(percent, 0, 100) / 100;
|
|
1388
|
+
const invertComponent = (color) => {
|
|
1389
|
+
const inverted = color * (1 - p) + (255 - color) * p;
|
|
1390
|
+
return Math.round(clamp(inverted, 0, 255));
|
|
1391
|
+
};
|
|
1392
|
+
const invertedR = invertComponent(r);
|
|
1393
|
+
const invertedG = invertComponent(g);
|
|
1394
|
+
const invertedB = invertComponent(b);
|
|
1395
|
+
return { r: invertedR, g: invertedG, b: invertedB };
|
|
1396
|
+
};
|
|
1397
|
+
var applyDarkModeFilter = (color) => {
|
|
1398
|
+
const cached = DARK_MODE_COLORS_CACHE?.get(color);
|
|
1399
|
+
if (cached) {
|
|
1400
|
+
return cached;
|
|
1401
|
+
}
|
|
1402
|
+
const tc = tinycolor(color);
|
|
1403
|
+
const alpha = tc.getAlpha();
|
|
1404
|
+
const rgb = tc.toRgb();
|
|
1405
|
+
const inverted = cssInvert(rgb.r, rgb.g, rgb.b, 93);
|
|
1406
|
+
const rotated = cssHueRotate(
|
|
1407
|
+
inverted.r,
|
|
1408
|
+
inverted.g,
|
|
1409
|
+
inverted.b,
|
|
1410
|
+
180
|
|
1411
|
+
);
|
|
1412
|
+
const result = rgbToHex2(rotated.r, rotated.g, rotated.b, alpha);
|
|
1413
|
+
if (DARK_MODE_COLORS_CACHE) {
|
|
1414
|
+
DARK_MODE_COLORS_CACHE.set(color, result);
|
|
1415
|
+
}
|
|
1416
|
+
return result;
|
|
1417
|
+
};
|
|
533
1418
|
var pick = (source, keys) => {
|
|
534
1419
|
return keys.reduce((acc, key) => {
|
|
535
1420
|
if (key in source) {
|
|
@@ -543,28 +1428,24 @@ var COLORS_PER_ROW = 5;
|
|
|
543
1428
|
var DEFAULT_CHART_COLOR_INDEX = 4;
|
|
544
1429
|
var DEFAULT_ELEMENT_STROKE_COLOR_INDEX = 4;
|
|
545
1430
|
var DEFAULT_ELEMENT_BACKGROUND_COLOR_INDEX = 1;
|
|
546
|
-
var ELEMENTS_PALETTE_SHADE_INDEXES = [0, 2, 4, 6, 8];
|
|
547
|
-
var CANVAS_PALETTE_SHADE_INDEXES = [0, 1, 2, 3, 4];
|
|
548
|
-
var getSpecificColorShades = (color, indexArr) => {
|
|
549
|
-
return indexArr.map((index) => open_color_default[color][index]);
|
|
550
|
-
};
|
|
551
1431
|
var COLOR_PALETTE = {
|
|
552
1432
|
transparent: "transparent",
|
|
553
1433
|
black: "#1e1e1e",
|
|
554
1434
|
white: "#ffffff",
|
|
555
|
-
// open-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
1435
|
+
// open-color from https://github.com/yeun/open-color/blob/master/open-color.js
|
|
1436
|
+
// corresponds to indexes [0,2,4,6,8] (weights: 50, 200, 400, 600, 800)
|
|
1437
|
+
gray: ["#f8f9fa", "#e9ecef", "#ced4da", "#868e96", "#343a40"],
|
|
1438
|
+
red: ["#fff5f5", "#ffc9c9", "#ff8787", "#fa5252", "#e03131"],
|
|
1439
|
+
pink: ["#fff0f6", "#fcc2d7", "#f783ac", "#e64980", "#c2255c"],
|
|
1440
|
+
grape: ["#f8f0fc", "#eebefa", "#da77f2", "#be4bdb", "#9c36b5"],
|
|
1441
|
+
violet: ["#f3f0ff", "#d0bfff", "#9775fa", "#7950f2", "#6741d9"],
|
|
1442
|
+
blue: ["#e7f5ff", "#a5d8ff", "#4dabf7", "#228be6", "#1971c2"],
|
|
1443
|
+
cyan: ["#e3fafc", "#99e9f2", "#3bc9db", "#15aabf", "#0c8599"],
|
|
1444
|
+
teal: ["#e6fcf5", "#96f2d7", "#38d9a9", "#12b886", "#099268"],
|
|
1445
|
+
green: ["#ebfbee", "#b2f2bb", "#69db7c", "#40c057", "#2f9e44"],
|
|
1446
|
+
yellow: ["#fff9db", "#ffec99", "#ffd43b", "#fab005", "#f08c00"],
|
|
1447
|
+
orange: ["#fff4e6", "#ffd8a8", "#ffa94d", "#fd7e14", "#e8590c"],
|
|
1448
|
+
// radix bronze shades [3,5,7,9,11]
|
|
568
1449
|
bronze: ["#f8f1ee", "#eaddd7", "#d2bab0", "#a18072", "#846358"]
|
|
569
1450
|
};
|
|
570
1451
|
var COMMON_ELEMENT_SHADES = pick(COLOR_PALETTE, [
|
|
@@ -636,22 +1517,61 @@ var getAllColorsSpecificShade = (index) => [
|
|
|
636
1517
|
COLOR_PALETTE.orange[index],
|
|
637
1518
|
COLOR_PALETTE.red[index]
|
|
638
1519
|
];
|
|
639
|
-
var
|
|
1520
|
+
var rgbToHex2 = (r, g, b, a) => {
|
|
1521
|
+
const hex6 = `#${((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1)}`;
|
|
1522
|
+
if (a !== void 0 && a < 1) {
|
|
1523
|
+
const alphaHex = Math.round(a * 255).toString(16).padStart(2, "0");
|
|
1524
|
+
return `${hex6}${alphaHex}`;
|
|
1525
|
+
}
|
|
1526
|
+
return hex6;
|
|
1527
|
+
};
|
|
1528
|
+
var colorToHex = (color) => {
|
|
1529
|
+
const tc = tinycolor(color);
|
|
1530
|
+
if (!tc.isValid()) {
|
|
1531
|
+
return null;
|
|
1532
|
+
}
|
|
1533
|
+
const { r, g, b, a } = tc.toRgb();
|
|
1534
|
+
return rgbToHex2(r, g, b, a);
|
|
1535
|
+
};
|
|
1536
|
+
var isTransparent = (color) => {
|
|
1537
|
+
return tinycolor(color).getAlpha() === 0;
|
|
1538
|
+
};
|
|
1539
|
+
var COLOR_OUTLINE_CONTRAST_THRESHOLD = 240;
|
|
1540
|
+
var calculateContrast = (r, g, b) => {
|
|
1541
|
+
const yiq = (r * 299 + g * 587 + b * 114) / 1e3;
|
|
1542
|
+
return yiq;
|
|
1543
|
+
};
|
|
1544
|
+
var isColorDark = (color, threshold = 160) => {
|
|
1545
|
+
if (!color) {
|
|
1546
|
+
return true;
|
|
1547
|
+
}
|
|
1548
|
+
if (isTransparent(color)) {
|
|
1549
|
+
return false;
|
|
1550
|
+
}
|
|
1551
|
+
const tc = tinycolor(color);
|
|
1552
|
+
if (!tc.isValid()) {
|
|
1553
|
+
return true;
|
|
1554
|
+
}
|
|
1555
|
+
const { r, g, b } = tc.toRgb();
|
|
1556
|
+
return calculateContrast(r, g, b) < threshold;
|
|
1557
|
+
};
|
|
1558
|
+
var normalizeInputColor = (color) => {
|
|
1559
|
+
color = color.trim();
|
|
1560
|
+
if (isTransparent(color)) {
|
|
1561
|
+
return color;
|
|
1562
|
+
}
|
|
1563
|
+
const tc = tinycolor(color);
|
|
1564
|
+
if (tc.isValid()) {
|
|
1565
|
+
if (tc.getFormat() === "hex" && !color.startsWith("#")) {
|
|
1566
|
+
return `#${color}`;
|
|
1567
|
+
}
|
|
1568
|
+
return color;
|
|
1569
|
+
}
|
|
1570
|
+
return null;
|
|
1571
|
+
};
|
|
640
1572
|
|
|
641
1573
|
// src/constants.ts
|
|
642
1574
|
init_define_import_meta_env();
|
|
643
|
-
var isDarwin = /Mac|iPod|iPhone|iPad/.test(navigator.platform);
|
|
644
|
-
var isWindows = /^Win/.test(navigator.platform);
|
|
645
|
-
var isAndroid = /\b(android)\b/i.test(navigator.userAgent);
|
|
646
|
-
var isFirefox = typeof window !== "undefined" && "netscape" in window && navigator.userAgent.indexOf("rv:") > 1 && navigator.userAgent.indexOf("Gecko") > 1;
|
|
647
|
-
var isChrome = navigator.userAgent.indexOf("Chrome") !== -1;
|
|
648
|
-
var isSafari = !isChrome && navigator.userAgent.indexOf("Safari") !== -1;
|
|
649
|
-
var isIOS = /iPad|iPhone/i.test(navigator.platform) || // iPadOS 13+
|
|
650
|
-
navigator.userAgent.includes("Mac") && "ontouchend" in document;
|
|
651
|
-
var isBrave = () => navigator.brave?.isBrave?.name === "isBrave";
|
|
652
|
-
var isMobile = isIOS || /android|webos|ipod|blackberry|iemobile|opera mini/i.test(
|
|
653
|
-
navigator.userAgent
|
|
654
|
-
) || /android|ios|ipod|blackberry|windows phone/i.test(navigator.platform);
|
|
655
1575
|
var supportsResizeObserver = typeof window !== "undefined" && "ResizeObserver" in window;
|
|
656
1576
|
var APP_NAME = "Excalidraw";
|
|
657
1577
|
var TEXT_AUTOWRAP_THRESHOLD = 36;
|
|
@@ -738,7 +1658,14 @@ var CLASSES = {
|
|
|
738
1658
|
ZOOM_ACTIONS: "zoom-actions",
|
|
739
1659
|
SEARCH_MENU_INPUT_WRAPPER: "layer-ui__search-inputWrapper",
|
|
740
1660
|
CONVERT_ELEMENT_TYPE_POPUP: "ConvertElementTypePopup",
|
|
741
|
-
SHAPE_ACTIONS_THEME_SCOPE: "shape-actions-theme-scope"
|
|
1661
|
+
SHAPE_ACTIONS_THEME_SCOPE: "shape-actions-theme-scope",
|
|
1662
|
+
FRAME_NAME: "frame-name"
|
|
1663
|
+
};
|
|
1664
|
+
var FONT_SIZES = {
|
|
1665
|
+
sm: 16,
|
|
1666
|
+
md: 20,
|
|
1667
|
+
lg: 28,
|
|
1668
|
+
xl: 36
|
|
742
1669
|
};
|
|
743
1670
|
var CJK_HAND_DRAWN_FALLBACK_FONT = "Xiaolai";
|
|
744
1671
|
var WINDOWS_EMOJI_FALLBACK_FONT = "Segoe UI Emoji";
|
|
@@ -883,7 +1810,6 @@ var MAX_ZOOM = 30;
|
|
|
883
1810
|
var HYPERLINK_TOOLTIP_DELAY = 300;
|
|
884
1811
|
var IDLE_THRESHOLD = 6e4;
|
|
885
1812
|
var ACTIVE_THRESHOLD = 3e3;
|
|
886
|
-
var THEME_FILTER = "invert(93%) hue-rotate(180deg)";
|
|
887
1813
|
var URL_QUERY_KEYS = {
|
|
888
1814
|
addLibrary: "addLibrary"
|
|
889
1815
|
};
|
|
@@ -904,13 +1830,6 @@ var DEFAULT_UI_OPTIONS = {
|
|
|
904
1830
|
image: true
|
|
905
1831
|
}
|
|
906
1832
|
};
|
|
907
|
-
var MQ_MAX_MOBILE = 599;
|
|
908
|
-
var MQ_MAX_WIDTH_LANDSCAPE = 1e3;
|
|
909
|
-
var MQ_MAX_HEIGHT_LANDSCAPE = 500;
|
|
910
|
-
var MQ_MIN_TABLET = MQ_MAX_MOBILE + 1;
|
|
911
|
-
var MQ_MAX_TABLET = 1400;
|
|
912
|
-
var MQ_MIN_WIDTH_DESKTOP = 1440;
|
|
913
|
-
var MQ_RIGHT_SIDEBAR_MIN_WIDTH = 1229;
|
|
914
1833
|
var MAX_DECIMALS_FOR_SVG_EXPORT = 2;
|
|
915
1834
|
var EXPORT_SCALES = [1, 2, 3];
|
|
916
1835
|
var DEFAULT_EXPORT_PADDING = 10;
|
|
@@ -1031,6 +1950,7 @@ var UserIdleState = /* @__PURE__ */ ((UserIdleState2) => {
|
|
|
1031
1950
|
})(UserIdleState || {});
|
|
1032
1951
|
var LINE_POLYGON_POINT_MERGE_DISTANCE = 20;
|
|
1033
1952
|
var DOUBLE_TAP_POSITION_THRESHOLD = 35;
|
|
1953
|
+
var BIND_MODE_TIMEOUT = 700;
|
|
1034
1954
|
var MOBILE_ACTION_BUTTON_BG = {
|
|
1035
1955
|
background: "var(--mobile-action-button-bg)"
|
|
1036
1956
|
};
|
|
@@ -1189,6 +2109,133 @@ var Queue = class {
|
|
|
1189
2109
|
|
|
1190
2110
|
// src/keys.ts
|
|
1191
2111
|
init_define_import_meta_env();
|
|
2112
|
+
|
|
2113
|
+
// src/editorInterface.ts
|
|
2114
|
+
init_define_import_meta_env();
|
|
2115
|
+
var DESKTOP_UI_MODE_STORAGE_KEY = "excalidraw.desktopUIMode";
|
|
2116
|
+
var MQ_MAX_MOBILE = 599;
|
|
2117
|
+
var MQ_MAX_WIDTH_LANDSCAPE = 1e3;
|
|
2118
|
+
var MQ_MAX_HEIGHT_LANDSCAPE = 500;
|
|
2119
|
+
var MQ_MIN_TABLET = MQ_MAX_MOBILE + 1;
|
|
2120
|
+
var MQ_MAX_TABLET = 1180;
|
|
2121
|
+
var MQ_MIN_WIDTH_DESKTOP = 1440;
|
|
2122
|
+
var MQ_RIGHT_SIDEBAR_MIN_WIDTH = 1229;
|
|
2123
|
+
var isDarwin = /Mac|iPod|iPhone|iPad/.test(navigator.platform);
|
|
2124
|
+
var isWindows = /^Win/.test(navigator.platform);
|
|
2125
|
+
var isAndroid = /\b(android)\b/i.test(navigator.userAgent);
|
|
2126
|
+
var isFirefox = typeof window !== "undefined" && "netscape" in window && navigator.userAgent.indexOf("rv:") > 1 && navigator.userAgent.indexOf("Gecko") > 1;
|
|
2127
|
+
var isChrome = navigator.userAgent.indexOf("Chrome") !== -1;
|
|
2128
|
+
var isSafari = !isChrome && navigator.userAgent.indexOf("Safari") !== -1;
|
|
2129
|
+
var isIOS = /iPad|iPhone/i.test(navigator.platform) || // iPadOS 13+
|
|
2130
|
+
navigator.userAgent.includes("Mac") && "ontouchend" in document;
|
|
2131
|
+
var isBrave = () => navigator.brave?.isBrave?.name === "isBrave";
|
|
2132
|
+
var isMobileBreakpoint = (width, height) => {
|
|
2133
|
+
return width <= MQ_MAX_MOBILE || height < MQ_MAX_HEIGHT_LANDSCAPE && width < MQ_MAX_WIDTH_LANDSCAPE;
|
|
2134
|
+
};
|
|
2135
|
+
var isTabletBreakpoint = (editorWidth, editorHeight) => {
|
|
2136
|
+
const minSide = Math.min(editorWidth, editorHeight);
|
|
2137
|
+
const maxSide = Math.max(editorWidth, editorHeight);
|
|
2138
|
+
return minSide >= MQ_MIN_TABLET && maxSide <= MQ_MAX_TABLET;
|
|
2139
|
+
};
|
|
2140
|
+
var isMobileOrTablet = () => {
|
|
2141
|
+
const ua = navigator.userAgent || "";
|
|
2142
|
+
const platform = navigator.platform || "";
|
|
2143
|
+
const uaData = navigator.userAgentData;
|
|
2144
|
+
if (uaData) {
|
|
2145
|
+
const plat = (uaData.platform || "").toLowerCase();
|
|
2146
|
+
const isDesktopOS = plat === "windows" || plat === "macos" || plat === "linux" || plat === "chrome os";
|
|
2147
|
+
if (uaData.mobile === true) {
|
|
2148
|
+
return true;
|
|
2149
|
+
}
|
|
2150
|
+
if (uaData.mobile === false && plat === "android") {
|
|
2151
|
+
const looksTouchTablet = matchMedia?.("(hover: none)").matches && matchMedia?.("(pointer: coarse)").matches;
|
|
2152
|
+
return looksTouchTablet;
|
|
2153
|
+
}
|
|
2154
|
+
if (isDesktopOS) {
|
|
2155
|
+
return false;
|
|
2156
|
+
}
|
|
2157
|
+
}
|
|
2158
|
+
if (isIOS) {
|
|
2159
|
+
return true;
|
|
2160
|
+
}
|
|
2161
|
+
if (isAndroid) {
|
|
2162
|
+
const isAndroidPhone = /Mobile/i.test(ua);
|
|
2163
|
+
const isAndroidTablet = !isAndroidPhone;
|
|
2164
|
+
if (isAndroidPhone || isAndroidTablet) {
|
|
2165
|
+
const looksTouchTablet = matchMedia?.("(hover: none)").matches && matchMedia?.("(pointer: coarse)").matches;
|
|
2166
|
+
return looksTouchTablet;
|
|
2167
|
+
}
|
|
2168
|
+
}
|
|
2169
|
+
const looksDesktopPlatform = /Win|Linux|CrOS|Mac/.test(platform) || /Windows NT|X11|CrOS|Macintosh/.test(ua);
|
|
2170
|
+
if (looksDesktopPlatform) {
|
|
2171
|
+
return false;
|
|
2172
|
+
}
|
|
2173
|
+
return false;
|
|
2174
|
+
};
|
|
2175
|
+
var getFormFactor = (editorWidth, editorHeight) => {
|
|
2176
|
+
if (isMobileBreakpoint(editorWidth, editorHeight)) {
|
|
2177
|
+
return "phone";
|
|
2178
|
+
}
|
|
2179
|
+
if (isTabletBreakpoint(editorWidth, editorHeight)) {
|
|
2180
|
+
return "tablet";
|
|
2181
|
+
}
|
|
2182
|
+
return "desktop";
|
|
2183
|
+
};
|
|
2184
|
+
var deriveStylesPanelMode = (editorInterface) => {
|
|
2185
|
+
if (editorInterface.formFactor === "phone") {
|
|
2186
|
+
return "mobile";
|
|
2187
|
+
}
|
|
2188
|
+
if (editorInterface.formFactor === "tablet") {
|
|
2189
|
+
return "compact";
|
|
2190
|
+
}
|
|
2191
|
+
return editorInterface.desktopUIMode;
|
|
2192
|
+
};
|
|
2193
|
+
var createUserAgentDescriptor = (userAgentString) => {
|
|
2194
|
+
const normalizedUA = userAgentString ?? "";
|
|
2195
|
+
let platform = "unknown";
|
|
2196
|
+
if (isIOS) {
|
|
2197
|
+
platform = "ios";
|
|
2198
|
+
} else if (isAndroid) {
|
|
2199
|
+
platform = "android";
|
|
2200
|
+
} else if (normalizedUA) {
|
|
2201
|
+
platform = "other";
|
|
2202
|
+
}
|
|
2203
|
+
return {
|
|
2204
|
+
isMobileDevice: isMobileOrTablet(),
|
|
2205
|
+
platform
|
|
2206
|
+
};
|
|
2207
|
+
};
|
|
2208
|
+
var loadDesktopUIModePreference = () => {
|
|
2209
|
+
if (typeof window === "undefined") {
|
|
2210
|
+
return null;
|
|
2211
|
+
}
|
|
2212
|
+
try {
|
|
2213
|
+
const stored = window.localStorage.getItem(DESKTOP_UI_MODE_STORAGE_KEY);
|
|
2214
|
+
if (stored === "compact" || stored === "full") {
|
|
2215
|
+
return stored;
|
|
2216
|
+
}
|
|
2217
|
+
} catch (error) {
|
|
2218
|
+
}
|
|
2219
|
+
return null;
|
|
2220
|
+
};
|
|
2221
|
+
var persistDesktopUIMode = (mode) => {
|
|
2222
|
+
if (typeof window === "undefined") {
|
|
2223
|
+
return;
|
|
2224
|
+
}
|
|
2225
|
+
try {
|
|
2226
|
+
window.localStorage.setItem(DESKTOP_UI_MODE_STORAGE_KEY, mode);
|
|
2227
|
+
} catch (error) {
|
|
2228
|
+
}
|
|
2229
|
+
};
|
|
2230
|
+
var setDesktopUIMode = (mode) => {
|
|
2231
|
+
if (mode !== "compact" && mode !== "full") {
|
|
2232
|
+
return;
|
|
2233
|
+
}
|
|
2234
|
+
persistDesktopUIMode(mode);
|
|
2235
|
+
return mode;
|
|
2236
|
+
};
|
|
2237
|
+
|
|
2238
|
+
// src/keys.ts
|
|
1192
2239
|
var CODES = {
|
|
1193
2240
|
EQUAL: "Equal",
|
|
1194
2241
|
MINUS: "Minus",
|
|
@@ -1618,6 +2665,9 @@ var removeSelection = () => {
|
|
|
1618
2665
|
}
|
|
1619
2666
|
};
|
|
1620
2667
|
var distance = (x, y) => Math.abs(x - y);
|
|
2668
|
+
var isSelectionLikeTool = (type) => {
|
|
2669
|
+
return type === "selection" || type === "lasso";
|
|
2670
|
+
};
|
|
1621
2671
|
var updateActiveTool = (appState, data) => {
|
|
1622
2672
|
if (data.type === "custom") {
|
|
1623
2673
|
return {
|
|
@@ -1639,13 +2689,6 @@ var updateActiveTool = (appState, data) => {
|
|
|
1639
2689
|
var isFullScreen = () => document.fullscreenElement?.nodeName === "HTML";
|
|
1640
2690
|
var allowFullScreen = () => document.documentElement.requestFullscreen();
|
|
1641
2691
|
var exitFullScreen = () => document.exitFullscreen();
|
|
1642
|
-
var getShortcutKey = (shortcut) => {
|
|
1643
|
-
shortcut = shortcut.replace(/\bAlt\b/i, "Alt").replace(/\bShift\b/i, "Shift").replace(/\b(Enter|Return)\b/i, "Enter");
|
|
1644
|
-
if (isDarwin) {
|
|
1645
|
-
return shortcut.replace(/\bCtrlOrCmd\b/gi, "Cmd").replace(/\bAlt\b/i, "Option");
|
|
1646
|
-
}
|
|
1647
|
-
return shortcut.replace(/\bCtrlOrCmd\b/gi, "Ctrl");
|
|
1648
|
-
};
|
|
1649
2692
|
var viewportCoordsToSceneCoords = ({ clientX, clientY }, {
|
|
1650
2693
|
zoom,
|
|
1651
2694
|
offsetLeft,
|
|
@@ -1719,12 +2762,6 @@ var mapFind = (collection, iteratee) => {
|
|
|
1719
2762
|
}
|
|
1720
2763
|
return void 0;
|
|
1721
2764
|
};
|
|
1722
|
-
var isTransparent = (color) => {
|
|
1723
|
-
const isRGBTransparent = color.length === 5 && color.substr(4, 1) === "0";
|
|
1724
|
-
const isRRGGBBTransparent = color.length === 9 && color.substr(7, 2) === "00";
|
|
1725
|
-
return isRGBTransparent || isRRGGBBTransparent || color === COLOR_PALETTE.transparent;
|
|
1726
|
-
};
|
|
1727
|
-
var isBindingFallthroughEnabled = (el) => el.fillStyle !== "solid" || isTransparent(el.backgroundColor);
|
|
1728
2765
|
var resolvablePromise = () => {
|
|
1729
2766
|
let resolve;
|
|
1730
2767
|
let reject;
|
|
@@ -2045,9 +3082,9 @@ function getSvgPathFromStroke(points, closed = true) {
|
|
|
2045
3082
|
var normalizeEOL = (str) => {
|
|
2046
3083
|
return str.replace(/\r?\n|\r/g, "\n");
|
|
2047
3084
|
};
|
|
2048
|
-
|
|
3085
|
+
function toBrandedType(value) {
|
|
2049
3086
|
return value;
|
|
2050
|
-
}
|
|
3087
|
+
}
|
|
2051
3088
|
var promiseTry = async (fn, ...args) => {
|
|
2052
3089
|
return new Promise((resolve) => {
|
|
2053
3090
|
resolve(fn(...args));
|
|
@@ -2087,40 +3124,37 @@ var reduceToCommonValue = (collection, getValue) => {
|
|
|
2087
3124
|
}
|
|
2088
3125
|
return commonValue;
|
|
2089
3126
|
};
|
|
2090
|
-
var
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
}
|
|
2104
|
-
if (isDesktopOS) {
|
|
2105
|
-
return false;
|
|
2106
|
-
}
|
|
2107
|
-
}
|
|
2108
|
-
if (isIOS) {
|
|
2109
|
-
return true;
|
|
2110
|
-
}
|
|
2111
|
-
if (isAndroid) {
|
|
2112
|
-
const isAndroidPhone = /Mobile/i.test(ua);
|
|
2113
|
-
const isAndroidTablet = !isAndroidPhone;
|
|
2114
|
-
if (isAndroidPhone || isAndroidTablet) {
|
|
2115
|
-
const looksTouchTablet = matchMedia?.("(hover: none)").matches && matchMedia?.("(pointer: coarse)").matches;
|
|
2116
|
-
return looksTouchTablet;
|
|
3127
|
+
var FEATURE_FLAGS_STORAGE_KEY = "excalidraw-feature-flags";
|
|
3128
|
+
var DEFAULT_FEATURE_FLAGS = {
|
|
3129
|
+
COMPLEX_BINDINGS: false
|
|
3130
|
+
};
|
|
3131
|
+
var featureFlags = null;
|
|
3132
|
+
var getFeatureFlag = (flag) => {
|
|
3133
|
+
if (!featureFlags) {
|
|
3134
|
+
try {
|
|
3135
|
+
const serializedFlags = localStorage.getItem(FEATURE_FLAGS_STORAGE_KEY);
|
|
3136
|
+
if (serializedFlags) {
|
|
3137
|
+
const flags = JSON.parse(serializedFlags);
|
|
3138
|
+
featureFlags = flags ?? DEFAULT_FEATURE_FLAGS;
|
|
3139
|
+
}
|
|
3140
|
+
} catch {
|
|
2117
3141
|
}
|
|
2118
3142
|
}
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
3143
|
+
return (featureFlags || DEFAULT_FEATURE_FLAGS)[flag];
|
|
3144
|
+
};
|
|
3145
|
+
var setFeatureFlag = (flag, value) => {
|
|
3146
|
+
try {
|
|
3147
|
+
featureFlags = {
|
|
3148
|
+
...featureFlags || DEFAULT_FEATURE_FLAGS,
|
|
3149
|
+
[flag]: value
|
|
3150
|
+
};
|
|
3151
|
+
localStorage.setItem(
|
|
3152
|
+
FEATURE_FLAGS_STORAGE_KEY,
|
|
3153
|
+
JSON.stringify(featureFlags)
|
|
3154
|
+
);
|
|
3155
|
+
} catch (e) {
|
|
3156
|
+
console.error("unable to set feature flag", e);
|
|
2122
3157
|
}
|
|
2123
|
-
return false;
|
|
2124
3158
|
};
|
|
2125
3159
|
|
|
2126
3160
|
// src/random.ts
|
|
@@ -2202,10 +3236,10 @@ export {
|
|
|
2202
3236
|
ARROW_LABEL_FONT_SIZE_TO_MIN_WIDTH_RATIO,
|
|
2203
3237
|
ARROW_LABEL_WIDTH_FRACTION,
|
|
2204
3238
|
ARROW_TYPE,
|
|
3239
|
+
BIND_MODE_TIMEOUT,
|
|
2205
3240
|
BOUND_TEXT_PADDING,
|
|
2206
3241
|
BinaryHeap,
|
|
2207
3242
|
CANVAS_ONLY_ACTIONS,
|
|
2208
|
-
CANVAS_PALETTE_SHADE_INDEXES,
|
|
2209
3243
|
CANVAS_SEARCH_TAB,
|
|
2210
3244
|
CJK_HAND_DRAWN_FALLBACK_FONT,
|
|
2211
3245
|
CLASSES,
|
|
@@ -2247,7 +3281,6 @@ export {
|
|
|
2247
3281
|
DOUBLE_TAP_POSITION_THRESHOLD,
|
|
2248
3282
|
DRAGGING_THRESHOLD,
|
|
2249
3283
|
EDITOR_LS_KEYS,
|
|
2250
|
-
ELEMENTS_PALETTE_SHADE_INDEXES,
|
|
2251
3284
|
ELEMENT_LINK_KEY,
|
|
2252
3285
|
ELEMENT_READY_TO_ERASE_OPACITY,
|
|
2253
3286
|
ELEMENT_SHIFT_TRANSLATE_AMOUNT,
|
|
@@ -2264,6 +3297,7 @@ export {
|
|
|
2264
3297
|
FONT_FAMILY_FALLBACKS,
|
|
2265
3298
|
FONT_FAMILY_GENERIC_FALLBACKS,
|
|
2266
3299
|
FONT_METADATA,
|
|
3300
|
+
FONT_SIZES,
|
|
2267
3301
|
FRAME_STYLE,
|
|
2268
3302
|
GOOGLE_FONTS_RANGES,
|
|
2269
3303
|
HYPERLINK_TOOLTIP_DELAY,
|
|
@@ -2316,7 +3350,6 @@ export {
|
|
|
2316
3350
|
TEXT_AUTOWRAP_THRESHOLD,
|
|
2317
3351
|
TEXT_TO_CENTER_SNAP_THRESHOLD,
|
|
2318
3352
|
THEME,
|
|
2319
|
-
THEME_FILTER,
|
|
2320
3353
|
TITLE_TIMEOUT,
|
|
2321
3354
|
TOOL_TYPE,
|
|
2322
3355
|
TOUCH_CTX_MENU_TIMEOUT,
|
|
@@ -2331,6 +3364,7 @@ export {
|
|
|
2331
3364
|
ZOOM_STEP,
|
|
2332
3365
|
addEventListener,
|
|
2333
3366
|
allowFullScreen,
|
|
3367
|
+
applyDarkModeFilter,
|
|
2334
3368
|
arrayToList,
|
|
2335
3369
|
arrayToMap,
|
|
2336
3370
|
arrayToMapWithIndex,
|
|
@@ -2341,8 +3375,11 @@ export {
|
|
|
2341
3375
|
castArray,
|
|
2342
3376
|
chunk,
|
|
2343
3377
|
cloneJSON,
|
|
3378
|
+
colorToHex,
|
|
2344
3379
|
composeEventHandlers,
|
|
3380
|
+
createUserAgentDescriptor,
|
|
2345
3381
|
debounce,
|
|
3382
|
+
deriveStylesPanelMode,
|
|
2346
3383
|
distance,
|
|
2347
3384
|
easeOut,
|
|
2348
3385
|
easeToValuesRAF,
|
|
@@ -2354,18 +3391,18 @@ export {
|
|
|
2354
3391
|
getAllColorsSpecificShade,
|
|
2355
3392
|
getDateTime,
|
|
2356
3393
|
getExportSource,
|
|
3394
|
+
getFeatureFlag,
|
|
2357
3395
|
getFontFamilyFallbacks,
|
|
2358
3396
|
getFontFamilyString,
|
|
2359
3397
|
getFontString,
|
|
3398
|
+
getFormFactor,
|
|
2360
3399
|
getFrame,
|
|
2361
3400
|
getGenericFontFamilyFallback,
|
|
2362
3401
|
getGlobalCSSVariable,
|
|
2363
3402
|
getGridPoint,
|
|
2364
3403
|
getLineHeight,
|
|
2365
3404
|
getNearestScrollableContainer,
|
|
2366
|
-
getShortcutKey,
|
|
2367
3405
|
getSizeFromPoints,
|
|
2368
|
-
getSpecificColorShades,
|
|
2369
3406
|
getSvgPathFromStroke,
|
|
2370
3407
|
getUpdatedTimestamp,
|
|
2371
3408
|
getVersion,
|
|
@@ -2374,9 +3411,10 @@ export {
|
|
|
2374
3411
|
isAndroid,
|
|
2375
3412
|
isAnyTrue,
|
|
2376
3413
|
isArrowKey,
|
|
2377
|
-
|
|
3414
|
+
isBounds,
|
|
2378
3415
|
isBrave,
|
|
2379
3416
|
isChrome,
|
|
3417
|
+
isColorDark,
|
|
2380
3418
|
isDarwin,
|
|
2381
3419
|
isDevEnv,
|
|
2382
3420
|
isFirefox,
|
|
@@ -2387,8 +3425,7 @@ export {
|
|
|
2387
3425
|
isLatinChar,
|
|
2388
3426
|
isLocalLink,
|
|
2389
3427
|
isMemberOf,
|
|
2390
|
-
|
|
2391
|
-
isMobileOrTablet,
|
|
3428
|
+
isMobileBreakpoint,
|
|
2392
3429
|
isPrimitive,
|
|
2393
3430
|
isProdEnv,
|
|
2394
3431
|
isPromiseLike,
|
|
@@ -2396,13 +3433,16 @@ export {
|
|
|
2396
3433
|
isReadonlyArray,
|
|
2397
3434
|
isRunningInIframe,
|
|
2398
3435
|
isSafari,
|
|
3436
|
+
isSelectionLikeTool,
|
|
2399
3437
|
isServerEnv,
|
|
2400
3438
|
isShallowEqual,
|
|
3439
|
+
isTabletBreakpoint,
|
|
2401
3440
|
isTestEnv,
|
|
2402
3441
|
isToolIcon,
|
|
2403
3442
|
isTransparent,
|
|
2404
3443
|
isWindows,
|
|
2405
3444
|
isWritableElement,
|
|
3445
|
+
loadDesktopUIModePreference,
|
|
2406
3446
|
mapFind,
|
|
2407
3447
|
matchKey,
|
|
2408
3448
|
memoize,
|
|
@@ -2410,6 +3450,7 @@ export {
|
|
|
2410
3450
|
nFormatter,
|
|
2411
3451
|
nextAnimationFrame,
|
|
2412
3452
|
normalizeEOL,
|
|
3453
|
+
normalizeInputColor,
|
|
2413
3454
|
normalizeLink,
|
|
2414
3455
|
preventUnload,
|
|
2415
3456
|
promiseTry,
|
|
@@ -2421,11 +3462,13 @@ export {
|
|
|
2421
3462
|
rescalePoints,
|
|
2422
3463
|
reseed,
|
|
2423
3464
|
resolvablePromise,
|
|
2424
|
-
rgbToHex,
|
|
3465
|
+
rgbToHex2 as rgbToHex,
|
|
2425
3466
|
safelyParseJSON,
|
|
2426
3467
|
sceneCoordsToViewportCoords,
|
|
2427
3468
|
selectNode,
|
|
2428
3469
|
setDateTimeForTests,
|
|
3470
|
+
setDesktopUIMode,
|
|
3471
|
+
setFeatureFlag,
|
|
2429
3472
|
shouldMaintainAspectRatio,
|
|
2430
3473
|
shouldResizeFromCenter,
|
|
2431
3474
|
shouldRotateWithDiscreteAngle,
|