@webiny/lexical-editor 5.44.1-beta.0 → 5.45.0-beta.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/README.md +6 -12
- package/commands/image.d.ts +2 -2
- package/commands/image.js +2 -8
- package/commands/image.js.map +1 -1
- package/commands/index.d.ts +5 -4
- package/commands/index.js +5 -49
- package/commands/index.js.map +1 -1
- package/commands/list.d.ts +1 -1
- package/commands/list.js +4 -10
- package/commands/list.js.map +1 -1
- package/commands/quote.d.ts +1 -1
- package/commands/quote.js +2 -8
- package/commands/quote.js.map +1 -1
- package/commands/toolbar.js +2 -8
- package/commands/toolbar.js.map +1 -1
- package/commands/typography.d.ts +8 -0
- package/commands/typography.js +4 -0
- package/commands/typography.js.map +1 -0
- package/components/Editor/EnsureHeadingTagPlugin.js +10 -16
- package/components/Editor/EnsureHeadingTagPlugin.js.map +1 -1
- package/components/Editor/RichTextEditor.d.ts +12 -8
- package/components/Editor/RichTextEditor.js +89 -102
- package/components/Editor/RichTextEditor.js.map +1 -1
- package/components/Editor/normalizeInputValue.d.ts +1 -1
- package/components/Editor/normalizeInputValue.js +2 -8
- package/components/Editor/normalizeInputValue.js.map +1 -1
- package/components/LexicalEditorConfig/LexicalEditorConfig.d.ts +14 -16
- package/components/LexicalEditorConfig/LexicalEditorConfig.js +21 -69
- package/components/LexicalEditorConfig/LexicalEditorConfig.js.map +1 -1
- package/components/LexicalEditorConfig/components/Node.d.ts +1 -1
- package/components/LexicalEditorConfig/components/Node.js +17 -26
- package/components/LexicalEditorConfig/components/Node.js.map +1 -1
- package/components/LexicalEditorConfig/components/Plugin.js +17 -26
- package/components/LexicalEditorConfig/components/Plugin.js.map +1 -1
- package/components/LexicalEditorConfig/components/ToolbarElement.js +17 -26
- package/components/LexicalEditorConfig/components/ToolbarElement.js.map +1 -1
- package/components/LexicalHtmlRenderer.d.ts +4 -7
- package/components/LexicalHtmlRenderer.js +35 -53
- package/components/LexicalHtmlRenderer.js.map +1 -1
- package/components/Toolbar/StaticToolbar.css +416 -0
- package/components/Toolbar/StaticToolbar.d.ts +3 -1
- package/components/Toolbar/StaticToolbar.js +19 -23
- package/components/Toolbar/StaticToolbar.js.map +1 -1
- package/components/ToolbarActions/BoldAction.js +16 -21
- package/components/ToolbarActions/BoldAction.js.map +1 -1
- package/components/ToolbarActions/BulletListAction.js +25 -31
- package/components/ToolbarActions/BulletListAction.js.map +1 -1
- package/components/ToolbarActions/CodeHighlightAction.js +16 -21
- package/components/ToolbarActions/CodeHighlightAction.js.map +1 -1
- package/components/ToolbarActions/FontColorAction.js +32 -42
- package/components/ToolbarActions/FontColorAction.js.map +1 -1
- package/components/ToolbarActions/ImageAction.js +19 -34
- package/components/ToolbarActions/ImageAction.js.map +1 -1
- package/components/ToolbarActions/ItalicAction.js +16 -21
- package/components/ToolbarActions/ItalicAction.js.map +1 -1
- package/components/ToolbarActions/LinkAction.js +19 -24
- package/components/ToolbarActions/LinkAction.js.map +1 -1
- package/components/ToolbarActions/NumberedListAction.js +25 -36
- package/components/ToolbarActions/NumberedListAction.js.map +1 -1
- package/components/ToolbarActions/QuoteAction.js +20 -25
- package/components/ToolbarActions/QuoteAction.js.map +1 -1
- package/components/ToolbarActions/TextAlignmentAction.js +36 -45
- package/components/ToolbarActions/TextAlignmentAction.js.map +1 -1
- package/components/ToolbarActions/TypographyAction.js +57 -79
- package/components/ToolbarActions/TypographyAction.js.map +1 -1
- package/components/ToolbarActions/UnderlineAction.js +16 -21
- package/components/ToolbarActions/UnderlineAction.js.map +1 -1
- package/context/FontColorActionContext.js +2 -9
- package/context/FontColorActionContext.js.map +1 -1
- package/context/RichTextEditorContext.d.ts +6 -7
- package/context/RichTextEditorContext.js +28 -26
- package/context/RichTextEditorContext.js.map +1 -1
- package/context/SharedHistoryContext.d.ts +2 -2
- package/context/SharedHistoryContext.js +12 -20
- package/context/SharedHistoryContext.js.map +1 -1
- package/context/TextAlignmentActionContextProps.d.ts +1 -1
- package/context/TextAlignmentActionContextProps.js +2 -9
- package/context/TextAlignmentActionContextProps.js.map +1 -1
- package/context/TypographyActionContext.d.ts +3 -2
- package/context/TypographyActionContext.js +2 -9
- package/context/TypographyActionContext.js.map +1 -1
- package/exports/admin/lexical.d.ts +15 -0
- package/exports/admin/lexical.js +23 -0
- package/exports/admin/lexical.js.map +1 -0
- package/hooks/index.d.ts +7 -8
- package/hooks/index.js +7 -93
- package/hooks/index.js.map +1 -1
- package/hooks/useCurrentElement.d.ts +3 -3
- package/hooks/useCurrentElement.js +11 -18
- package/hooks/useCurrentElement.js.map +1 -1
- package/hooks/useCurrentSelection.d.ts +2 -1
- package/hooks/useCurrentSelection.js +27 -40
- package/hooks/useCurrentSelection.js.map +1 -1
- package/hooks/useFontColorPicker.d.ts +1 -1
- package/hooks/useFontColorPicker.js +5 -11
- package/hooks/useFontColorPicker.js.map +1 -1
- package/hooks/useIsMounted.js +6 -14
- package/hooks/useIsMounted.js.map +1 -1
- package/hooks/useRichTextEditor.d.ts +1 -1
- package/hooks/useRichTextEditor.js +5 -11
- package/hooks/useRichTextEditor.js.map +1 -1
- package/hooks/useTextAlignmentAction.d.ts +1 -1
- package/hooks/useTextAlignmentAction.js +5 -11
- package/hooks/useTextAlignmentAction.js.map +1 -1
- package/hooks/useTypographyAction.d.ts +1 -1
- package/hooks/useTypographyAction.js +5 -11
- package/hooks/useTypographyAction.js.map +1 -1
- package/index.d.ts +33 -38
- package/index.js +44 -322
- package/index.js.map +1 -1
- package/package.json +18 -22
- package/plugins/BlurEventPlugin/BlurEventPlugin.d.ts +2 -2
- package/plugins/BlurEventPlugin/BlurEventPlugin.js +16 -22
- package/plugins/BlurEventPlugin/BlurEventPlugin.js.map +1 -1
- package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.js +9 -14
- package/plugins/CodeHighlightPlugin/CodeHighlightPlugin.js.map +1 -1
- package/plugins/CodeHighlightPlugin/index.d.ts +1 -1
- package/plugins/CodeHighlightPlugin/index.js +1 -16
- package/plugins/CodeHighlightPlugin/index.js.map +1 -1
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditor.d.ts +10 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditor.js +28 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditor.js.map +1 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorController.d.ts +7 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorController.js +61 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorController.js.map +1 -0
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.css +2 -136
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.d.ts +4 -16
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js +7 -180
- package/plugins/FloatingLinkEditorPlugin/FloatingLinkEditorPlugin.js.map +1 -1
- package/plugins/FloatingLinkEditorPlugin/index.d.ts +1 -1
- package/plugins/FloatingLinkEditorPlugin/index.js +1 -16
- package/plugins/FloatingLinkEditorPlugin/index.js.map +1 -1
- package/plugins/FloatingLinkEditorPlugin/isChildOfLinkEditor.js +3 -9
- package/plugins/FloatingLinkEditorPlugin/isChildOfLinkEditor.js.map +1 -1
- package/plugins/FloatingLinkEditorPlugin/types.d.ts +10 -0
- package/plugins/FloatingLinkEditorPlugin/types.js +3 -0
- package/plugins/FloatingLinkEditorPlugin/types.js.map +1 -0
- package/plugins/FloatingLinkEditorPlugin/useFloatingLinkEditor.d.ts +8 -2
- package/plugins/FloatingLinkEditorPlugin/useFloatingLinkEditor.js +120 -88
- package/plugins/FloatingLinkEditorPlugin/useFloatingLinkEditor.js.map +1 -1
- package/plugins/FontColorPlugin/FontColorPlugin.js +19 -22
- package/plugins/FontColorPlugin/FontColorPlugin.js.map +1 -1
- package/plugins/FontColorPlugin/applyColorToNode.d.ts +2 -2
- package/plugins/FontColorPlugin/applyColorToNode.js +4 -10
- package/plugins/FontColorPlugin/applyColorToNode.js.map +1 -1
- package/plugins/FontColorPlugin/applyColorToSelection.d.ts +2 -2
- package/plugins/FontColorPlugin/applyColorToSelection.js +28 -44
- package/plugins/FontColorPlugin/applyColorToSelection.js.map +1 -1
- package/plugins/ImagesPlugin/ImagesPlugin.d.ts +1 -2
- package/plugins/ImagesPlugin/ImagesPlugin.js +58 -60
- package/plugins/ImagesPlugin/ImagesPlugin.js.map +1 -1
- package/plugins/LinkPlugin/LinkPlugin.js +29 -37
- package/plugins/LinkPlugin/LinkPlugin.js.map +1 -1
- package/plugins/ListPLugin/ListPlugin.js +52 -15
- package/plugins/ListPLugin/ListPlugin.js.map +1 -1
- package/plugins/QuoteNodePlugin/QuoteNodePlugin.js +19 -16
- package/plugins/QuoteNodePlugin/QuoteNodePlugin.js.map +1 -1
- package/plugins/StateHandlingPlugin.d.ts +1 -1
- package/plugins/StateHandlingPlugin.js +32 -39
- package/plugins/StateHandlingPlugin.js.map +1 -1
- package/plugins/TypographyPlugin/TypographyPlugin.js +17 -21
- package/plugins/TypographyPlugin/TypographyPlugin.js.map +1 -1
- package/types.d.ts +4 -4
- package/types.js +6 -38
- package/types.js.map +1 -1
- package/ui/ContentEditable.d.ts +0 -1
- package/ui/ContentEditable.js +7 -14
- package/ui/ContentEditable.js.map +1 -1
- package/ui/Divider.d.ts +0 -1
- package/ui/Divider.js +3 -10
- package/ui/Divider.js.map +1 -1
- package/ui/DropDown.d.ts +1 -1
- package/ui/DropDown.js +64 -90
- package/ui/DropDown.js.map +1 -1
- package/ui/ImageResizer.d.ts +0 -1
- package/ui/ImageResizer.js +78 -83
- package/ui/ImageResizer.js.map +1 -1
- package/ui/LinkPreview.d.ts +0 -1
- package/ui/LinkPreview.js +22 -29
- package/ui/LinkPreview.js.map +1 -1
- package/ui/Placeholder.d.ts +1 -1
- package/ui/Placeholder.js +10 -16
- package/ui/Placeholder.js.map +1 -1
- package/ui/TextInput.d.ts +0 -1
- package/ui/TextInput.js +11 -18
- package/ui/TextInput.js.map +1 -1
- package/ui/ToolbarActionDialog.js +30 -42
- package/ui/ToolbarActionDialog.js.map +1 -1
- package/utils/canUseDOM.js +1 -7
- package/utils/canUseDOM.js.map +1 -1
- package/utils/files.d.ts +6 -6
- package/utils/files.js +5 -32
- package/utils/files.js.map +1 -1
- package/utils/getDOMRangeRect.js +4 -10
- package/utils/getDOMRangeRect.js.map +1 -1
- package/utils/getSelectedNode.d.ts +1 -1
- package/utils/getSelectedNode.js +9 -16
- package/utils/getSelectedNode.js.map +1 -1
- package/utils/getTransparentImage.js +1 -7
- package/utils/getTransparentImage.js.map +1 -1
- package/utils/insertImage.d.ts +1 -1
- package/utils/insertImage.js +8 -14
- package/utils/insertImage.js.map +1 -1
- package/utils/isAnchorLink.js +1 -7
- package/utils/isAnchorLink.js.map +1 -1
- package/utils/isChildOfFloatingToolbar.js +3 -12
- package/utils/isChildOfFloatingToolbar.js.map +1 -1
- package/utils/isHTMLElement.js +1 -7
- package/utils/isHTMLElement.js.map +1 -1
- package/utils/isValidJSON.js +3 -9
- package/utils/isValidJSON.js.map +1 -1
- package/utils/isValidLexicalData.d.ts +3 -3
- package/utils/isValidLexicalData.js +6 -12
- package/utils/isValidLexicalData.js.map +1 -1
- package/utils/point.js +35 -60
- package/utils/point.js.map +1 -1
- package/utils/rect.d.ts +1 -1
- package/utils/rect.js +115 -149
- package/utils/rect.js.map +1 -1
- package/utils/sanitizeUrl.js +6 -13
- package/utils/sanitizeUrl.js.map +1 -1
- package/utils/setFloatingElemPosition.d.ts +1 -1
- package/utils/setFloatingElemPosition.js +24 -30
- package/utils/setFloatingElemPosition.js.map +1 -1
- package/components/Editor/HeadingEditor.d.ts +0 -7
- package/components/Editor/HeadingEditor.js +0 -30
- package/components/Editor/HeadingEditor.js.map +0 -1
- package/components/Editor/ParagraphEditor.d.ts +0 -7
- package/components/Editor/ParagraphEditor.js +0 -29
- package/components/Editor/ParagraphEditor.js.map +0 -1
- package/components/Toolbar/Toolbar.css +0 -643
- package/components/Toolbar/Toolbar.d.ts +0 -11
- package/components/Toolbar/Toolbar.js +0 -165
- package/components/Toolbar/Toolbar.js.map +0 -1
- package/components/ToolbarActions/FontSizeAction.d.ts +0 -14
- package/components/ToolbarActions/FontSizeAction.js +0 -109
- package/components/ToolbarActions/FontSizeAction.js.map +0 -1
- package/hooks/useList.d.ts +0 -2
- package/hooks/useList.js +0 -54
- package/hooks/useList.js.map +0 -1
- package/hooks/useQuote.d.ts +0 -2
- package/hooks/useQuote.js +0 -22
- package/hooks/useQuote.js.map +0 -1
- package/plugins/FloatingLinkEditorPlugin/LinkEditForm.d.ts +0 -9
- package/plugins/FloatingLinkEditorPlugin/LinkEditForm.js +0 -118
- package/plugins/FloatingLinkEditorPlugin/LinkEditForm.js.map +0 -1
- package/plugins/FloatingLinkEditorPlugin/LinkPreviewForm.d.ts +0 -9
- package/plugins/FloatingLinkEditorPlugin/LinkPreviewForm.js +0 -44
- package/plugins/FloatingLinkEditorPlugin/LinkPreviewForm.js.map +0 -1
- package/utils/generateInitialLexicalValue.d.ts +0 -4
- package/utils/generateInitialLexicalValue.js +0 -33
- package/utils/generateInitialLexicalValue.js.map +0 -1
package/utils/isValidJSON.js
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.isValidJSON = void 0;
|
|
7
|
-
var isValidJSON = exports.isValidJSON = function isValidJSON(value) {
|
|
1
|
+
export const isValidJSON = value => {
|
|
8
2
|
if (!value) {
|
|
9
3
|
return false;
|
|
10
4
|
}
|
|
11
5
|
try {
|
|
12
|
-
|
|
6
|
+
const o = JSON.parse(value);
|
|
13
7
|
return !!o && typeof o === "object" && !Array.isArray(o);
|
|
14
|
-
} catch
|
|
8
|
+
} catch {
|
|
15
9
|
return false;
|
|
16
10
|
}
|
|
17
11
|
};
|
package/utils/isValidJSON.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["isValidJSON","
|
|
1
|
+
{"version":3,"names":["isValidJSON","value","o","JSON","parse","Array","isArray"],"sources":["isValidJSON.ts"],"sourcesContent":["export const isValidJSON = (value: string | undefined | null): boolean => {\n if (!value) {\n return false;\n }\n try {\n const o = JSON.parse(value);\n return !!o && typeof o === \"object\" && !Array.isArray(o);\n } catch {\n return false;\n }\n};\n"],"mappings":"AAAA,OAAO,MAAMA,WAAW,GAAIC,KAAgC,IAAc;EACtE,IAAI,CAACA,KAAK,EAAE;IACR,OAAO,KAAK;EAChB;EACA,IAAI;IACA,MAAMC,CAAC,GAAGC,IAAI,CAACC,KAAK,CAACH,KAAK,CAAC;IAC3B,OAAO,CAAC,CAACC,CAAC,IAAI,OAAOA,CAAC,KAAK,QAAQ,IAAI,CAACG,KAAK,CAACC,OAAO,CAACJ,CAAC,CAAC;EAC5D,CAAC,CAAC,MAAM;IACJ,OAAO,KAAK;EAChB;AACJ,CAAC","ignoreList":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SerializedEditorState } from "lexical";
|
|
2
|
-
import { LexicalValue } from "../types";
|
|
1
|
+
import type { SerializedEditorState } from "lexical";
|
|
2
|
+
import type { LexicalValue } from "../types.js";
|
|
3
3
|
export declare const parseLexicalState: (editorStateValue: LexicalValue | null) => false | SerializedEditorState;
|
|
4
|
-
export declare const isValidLexicalData: (editorStateValue: LexicalValue | null) =>
|
|
4
|
+
export declare const isValidLexicalData: (editorStateValue: LexicalValue | null) => editorStateValue is LexicalValue;
|
|
@@ -1,28 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.parseLexicalState = exports.isValidLexicalData = void 0;
|
|
7
|
-
var parseLexicalState = exports.parseLexicalState = function parseLexicalState(editorStateValue) {
|
|
1
|
+
export const parseLexicalState = editorStateValue => {
|
|
8
2
|
if (!editorStateValue) {
|
|
9
3
|
return false;
|
|
10
4
|
}
|
|
11
5
|
try {
|
|
12
|
-
|
|
6
|
+
const maybeValidState = JSON.parse(editorStateValue);
|
|
13
7
|
return maybeValidState["root"] ? maybeValidState : false;
|
|
14
|
-
} catch
|
|
8
|
+
} catch {
|
|
15
9
|
return false;
|
|
16
10
|
}
|
|
17
11
|
};
|
|
18
|
-
|
|
12
|
+
export const isValidLexicalData = editorStateValue => {
|
|
19
13
|
if (!editorStateValue) {
|
|
20
14
|
return false;
|
|
21
15
|
}
|
|
22
16
|
try {
|
|
23
|
-
|
|
17
|
+
const data = JSON.parse(editorStateValue);
|
|
24
18
|
return !!data["root"];
|
|
25
|
-
} catch
|
|
19
|
+
} catch {
|
|
26
20
|
return false;
|
|
27
21
|
}
|
|
28
22
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["parseLexicalState","
|
|
1
|
+
{"version":3,"names":["parseLexicalState","editorStateValue","maybeValidState","JSON","parse","isValidLexicalData","data"],"sources":["isValidLexicalData.ts"],"sourcesContent":["import type { SerializedEditorState } from \"lexical\";\nimport type { LexicalValue } from \"~/types.js\";\n\nexport const parseLexicalState = (\n editorStateValue: LexicalValue | null\n): false | SerializedEditorState => {\n if (!editorStateValue) {\n return false;\n }\n try {\n const maybeValidState = JSON.parse(editorStateValue);\n return maybeValidState[\"root\"] ? maybeValidState : false;\n } catch {\n return false;\n }\n};\n\nexport const isValidLexicalData = (\n editorStateValue: LexicalValue | null\n): editorStateValue is LexicalValue => {\n if (!editorStateValue) {\n return false;\n }\n\n try {\n const data = JSON.parse(editorStateValue);\n return !!data[\"root\"];\n } catch {\n return false;\n }\n};\n"],"mappings":"AAGA,OAAO,MAAMA,iBAAiB,GAC1BC,gBAAqC,IACL;EAChC,IAAI,CAACA,gBAAgB,EAAE;IACnB,OAAO,KAAK;EAChB;EACA,IAAI;IACA,MAAMC,eAAe,GAAGC,IAAI,CAACC,KAAK,CAACH,gBAAgB,CAAC;IACpD,OAAOC,eAAe,CAAC,MAAM,CAAC,GAAGA,eAAe,GAAG,KAAK;EAC5D,CAAC,CAAC,MAAM;IACJ,OAAO,KAAK;EAChB;AACJ,CAAC;AAED,OAAO,MAAMG,kBAAkB,GAC3BJ,gBAAqC,IACF;EACnC,IAAI,CAACA,gBAAgB,EAAE;IACnB,OAAO,KAAK;EAChB;EAEA,IAAI;IACA,MAAMK,IAAI,GAAGH,IAAI,CAACC,KAAK,CAACH,gBAAgB,CAAC;IACzC,OAAO,CAAC,CAACK,IAAI,CAAC,MAAM,CAAC;EACzB,CAAC,CAAC,MAAM;IACJ,OAAO,KAAK;EAChB;AACJ,CAAC","ignoreList":[]}
|
package/utils/point.js
CHANGED
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.Point = void 0;
|
|
8
|
-
exports.isPoint = isPoint;
|
|
9
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
10
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
11
1
|
/**
|
|
12
2
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
13
3
|
*
|
|
@@ -15,59 +5,44 @@ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/creat
|
|
|
15
5
|
* LICENSE file in the root directory of this source tree.
|
|
16
6
|
*
|
|
17
7
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
(0, _classCallCheck2.default)(this, Point);
|
|
8
|
+
export class Point {
|
|
9
|
+
constructor(x, y) {
|
|
21
10
|
this._x = x;
|
|
22
11
|
this._y = y;
|
|
23
12
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
}, {
|
|
59
|
-
key: "calcVerticalDistance",
|
|
60
|
-
value: function calcVerticalDistance(point) {
|
|
61
|
-
return Math.abs(this.calcDeltaYTo(point));
|
|
62
|
-
}
|
|
63
|
-
}, {
|
|
64
|
-
key: "calcDistanceTo",
|
|
65
|
-
value: function calcDistanceTo(point) {
|
|
66
|
-
return Math.sqrt(Math.pow(this.calcDeltaXTo(point), 2) + Math.pow(this.calcDeltaYTo(point), 2));
|
|
67
|
-
}
|
|
68
|
-
}]);
|
|
69
|
-
}();
|
|
70
|
-
function isPoint(x) {
|
|
13
|
+
get x() {
|
|
14
|
+
return this._x;
|
|
15
|
+
}
|
|
16
|
+
get y() {
|
|
17
|
+
return this._y;
|
|
18
|
+
}
|
|
19
|
+
equals({
|
|
20
|
+
x,
|
|
21
|
+
y
|
|
22
|
+
}) {
|
|
23
|
+
return this.x === x && this.y === y;
|
|
24
|
+
}
|
|
25
|
+
calcDeltaXTo({
|
|
26
|
+
x
|
|
27
|
+
}) {
|
|
28
|
+
return this.x - x;
|
|
29
|
+
}
|
|
30
|
+
calcDeltaYTo({
|
|
31
|
+
y
|
|
32
|
+
}) {
|
|
33
|
+
return this.y - y;
|
|
34
|
+
}
|
|
35
|
+
calcHorizontalDistanceTo(point) {
|
|
36
|
+
return Math.abs(this.calcDeltaXTo(point));
|
|
37
|
+
}
|
|
38
|
+
calcVerticalDistance(point) {
|
|
39
|
+
return Math.abs(this.calcDeltaYTo(point));
|
|
40
|
+
}
|
|
41
|
+
calcDistanceTo(point) {
|
|
42
|
+
return Math.sqrt(Math.pow(this.calcDeltaXTo(point), 2) + Math.pow(this.calcDeltaYTo(point), 2));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export function isPoint(x) {
|
|
71
46
|
return x instanceof Point;
|
|
72
47
|
}
|
|
73
48
|
|
package/utils/point.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Point","
|
|
1
|
+
{"version":3,"names":["Point","constructor","x","y","_x","_y","equals","calcDeltaXTo","calcDeltaYTo","calcHorizontalDistanceTo","point","Math","abs","calcVerticalDistance","calcDistanceTo","sqrt","pow","isPoint"],"sources":["point.ts"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\nexport class Point {\n private readonly _x: number;\n private readonly _y: number;\n\n constructor(x: number, y: number) {\n this._x = x;\n this._y = y;\n }\n\n get x(): number {\n return this._x;\n }\n\n get y(): number {\n return this._y;\n }\n\n public equals({ x, y }: Point): boolean {\n return this.x === x && this.y === y;\n }\n\n public calcDeltaXTo({ x }: Point): number {\n return this.x - x;\n }\n\n public calcDeltaYTo({ y }: Point): number {\n return this.y - y;\n }\n\n public calcHorizontalDistanceTo(point: Point): number {\n return Math.abs(this.calcDeltaXTo(point));\n }\n\n public calcVerticalDistance(point: Point): number {\n return Math.abs(this.calcDeltaYTo(point));\n }\n\n public calcDistanceTo(point: Point): number {\n return Math.sqrt(\n Math.pow(this.calcDeltaXTo(point), 2) + Math.pow(this.calcDeltaYTo(point), 2)\n );\n }\n}\n\nexport function isPoint(x: unknown): x is Point {\n return x instanceof Point;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,KAAK,CAAC;EAIfC,WAAWA,CAACC,CAAS,EAAEC,CAAS,EAAE;IAC9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
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.Rect = void 0;
|
|
8
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
10
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
11
|
-
var _point = require("./point");
|
|
12
1
|
/**
|
|
13
2
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
14
3
|
*
|
|
@@ -16,149 +5,126 @@ var _point = require("./point");
|
|
|
16
5
|
* LICENSE file in the root directory of this source tree.
|
|
17
6
|
*
|
|
18
7
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
physicBottom = _ref2[1];
|
|
26
|
-
var _ref3 = left <= right ? [left, right] : [right, left],
|
|
27
|
-
_ref4 = (0, _slicedToArray2.default)(_ref3, 2),
|
|
28
|
-
physicLeft = _ref4[0],
|
|
29
|
-
physicRight = _ref4[1];
|
|
8
|
+
|
|
9
|
+
import { isPoint } from "./point.js";
|
|
10
|
+
export class Rect {
|
|
11
|
+
constructor(left, top, right, bottom) {
|
|
12
|
+
const [physicTop, physicBottom] = top <= bottom ? [top, bottom] : [bottom, top];
|
|
13
|
+
const [physicLeft, physicRight] = left <= right ? [left, right] : [right, left];
|
|
30
14
|
this._top = physicTop;
|
|
31
15
|
this._right = physicRight;
|
|
32
16
|
this._left = physicLeft;
|
|
33
17
|
this._bottom = physicBottom;
|
|
34
18
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
isOnRightSide: isOnRightSide,
|
|
90
|
-
isOnTopSide: isOnTopSide
|
|
91
|
-
},
|
|
92
|
-
result: result
|
|
93
|
-
};
|
|
94
|
-
} else {
|
|
95
|
-
var top = target.top,
|
|
96
|
-
left = target.left,
|
|
97
|
-
bottom = target.bottom,
|
|
98
|
-
right = target.right;
|
|
99
|
-
return top >= this._top && top <= this._bottom && bottom >= this._top && bottom <= this._bottom && left >= this._left && left <= this._right && right >= this._left && right <= this._right;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}, {
|
|
103
|
-
key: "intersectsWith",
|
|
104
|
-
value: function intersectsWith(rect) {
|
|
105
|
-
var x1 = rect.left,
|
|
106
|
-
y1 = rect.top,
|
|
107
|
-
w1 = rect.width,
|
|
108
|
-
h1 = rect.height;
|
|
109
|
-
var x2 = this.left,
|
|
110
|
-
y2 = this.top,
|
|
111
|
-
w2 = this.width,
|
|
112
|
-
h2 = this.height;
|
|
113
|
-
var maxX = x1 + w1 >= x2 + w2 ? x1 + w1 : x2 + w2;
|
|
114
|
-
var maxY = y1 + h1 >= y2 + h2 ? y1 + h1 : y2 + h2;
|
|
115
|
-
var minX = x1 <= x2 ? x1 : x2;
|
|
116
|
-
var minY = y1 <= y2 ? y1 : y2;
|
|
117
|
-
return maxX - minX <= w1 + w2 && maxY - minY <= h1 + h2;
|
|
118
|
-
}
|
|
119
|
-
}, {
|
|
120
|
-
key: "generateNewRect",
|
|
121
|
-
value: function generateNewRect(_ref6) {
|
|
122
|
-
var _ref6$left = _ref6.left,
|
|
123
|
-
left = _ref6$left === void 0 ? this.left : _ref6$left,
|
|
124
|
-
_ref6$top = _ref6.top,
|
|
125
|
-
top = _ref6$top === void 0 ? this.top : _ref6$top,
|
|
126
|
-
_ref6$right = _ref6.right,
|
|
127
|
-
right = _ref6$right === void 0 ? this.right : _ref6$right,
|
|
128
|
-
_ref6$bottom = _ref6.bottom,
|
|
129
|
-
bottom = _ref6$bottom === void 0 ? this.bottom : _ref6$bottom;
|
|
130
|
-
return new Rect(left, top, right, bottom);
|
|
131
|
-
}
|
|
132
|
-
}], [{
|
|
133
|
-
key: "fromLTRB",
|
|
134
|
-
value: function fromLTRB(left, top, right, bottom) {
|
|
135
|
-
return new Rect(left, top, right, bottom);
|
|
136
|
-
}
|
|
137
|
-
}, {
|
|
138
|
-
key: "fromLWTH",
|
|
139
|
-
value: function fromLWTH(left, width, top, height) {
|
|
140
|
-
return new Rect(left, top, left + width, top + height);
|
|
141
|
-
}
|
|
142
|
-
}, {
|
|
143
|
-
key: "fromPoints",
|
|
144
|
-
value: function fromPoints(startPoint, endPoint) {
|
|
145
|
-
var top = startPoint.y,
|
|
146
|
-
left = startPoint.x;
|
|
147
|
-
var bottom = endPoint.y,
|
|
148
|
-
right = endPoint.x;
|
|
149
|
-
return Rect.fromLTRB(left, top, right, bottom);
|
|
150
|
-
}
|
|
151
|
-
}, {
|
|
152
|
-
key: "fromDOM",
|
|
153
|
-
value: function fromDOM(dom) {
|
|
154
|
-
var _dom$getBoundingClien = dom.getBoundingClientRect(),
|
|
155
|
-
top = _dom$getBoundingClien.top,
|
|
156
|
-
width = _dom$getBoundingClien.width,
|
|
157
|
-
left = _dom$getBoundingClien.left,
|
|
158
|
-
height = _dom$getBoundingClien.height;
|
|
159
|
-
return Rect.fromLWTH(left, width, top, height);
|
|
19
|
+
get top() {
|
|
20
|
+
return this._top;
|
|
21
|
+
}
|
|
22
|
+
get right() {
|
|
23
|
+
return this._right;
|
|
24
|
+
}
|
|
25
|
+
get bottom() {
|
|
26
|
+
return this._bottom;
|
|
27
|
+
}
|
|
28
|
+
get left() {
|
|
29
|
+
return this._left;
|
|
30
|
+
}
|
|
31
|
+
get width() {
|
|
32
|
+
return Math.abs(this._left - this._right);
|
|
33
|
+
}
|
|
34
|
+
get height() {
|
|
35
|
+
return Math.abs(this._bottom - this._top);
|
|
36
|
+
}
|
|
37
|
+
equals({
|
|
38
|
+
top,
|
|
39
|
+
left,
|
|
40
|
+
bottom,
|
|
41
|
+
right
|
|
42
|
+
}) {
|
|
43
|
+
return top === this._top && bottom === this._bottom && left === this._left && right === this._right;
|
|
44
|
+
}
|
|
45
|
+
contains(target) {
|
|
46
|
+
if (isPoint(target)) {
|
|
47
|
+
const {
|
|
48
|
+
x,
|
|
49
|
+
y
|
|
50
|
+
} = target;
|
|
51
|
+
const isOnTopSide = y < this._top;
|
|
52
|
+
const isOnBottomSide = y > this._bottom;
|
|
53
|
+
const isOnLeftSide = x < this._left;
|
|
54
|
+
const isOnRightSide = x > this._right;
|
|
55
|
+
const result = !isOnTopSide && !isOnBottomSide && !isOnLeftSide && !isOnRightSide;
|
|
56
|
+
return {
|
|
57
|
+
reason: {
|
|
58
|
+
isOnBottomSide,
|
|
59
|
+
isOnLeftSide,
|
|
60
|
+
isOnRightSide,
|
|
61
|
+
isOnTopSide
|
|
62
|
+
},
|
|
63
|
+
result
|
|
64
|
+
};
|
|
65
|
+
} else {
|
|
66
|
+
const {
|
|
67
|
+
top,
|
|
68
|
+
left,
|
|
69
|
+
bottom,
|
|
70
|
+
right
|
|
71
|
+
} = target;
|
|
72
|
+
return top >= this._top && top <= this._bottom && bottom >= this._top && bottom <= this._bottom && left >= this._left && left <= this._right && right >= this._left && right <= this._right;
|
|
160
73
|
}
|
|
161
|
-
}
|
|
162
|
-
|
|
74
|
+
}
|
|
75
|
+
intersectsWith(rect) {
|
|
76
|
+
const {
|
|
77
|
+
left: x1,
|
|
78
|
+
top: y1,
|
|
79
|
+
width: w1,
|
|
80
|
+
height: h1
|
|
81
|
+
} = rect;
|
|
82
|
+
const {
|
|
83
|
+
left: x2,
|
|
84
|
+
top: y2,
|
|
85
|
+
width: w2,
|
|
86
|
+
height: h2
|
|
87
|
+
} = this;
|
|
88
|
+
const maxX = x1 + w1 >= x2 + w2 ? x1 + w1 : x2 + w2;
|
|
89
|
+
const maxY = y1 + h1 >= y2 + h2 ? y1 + h1 : y2 + h2;
|
|
90
|
+
const minX = x1 <= x2 ? x1 : x2;
|
|
91
|
+
const minY = y1 <= y2 ? y1 : y2;
|
|
92
|
+
return maxX - minX <= w1 + w2 && maxY - minY <= h1 + h2;
|
|
93
|
+
}
|
|
94
|
+
generateNewRect({
|
|
95
|
+
left = this.left,
|
|
96
|
+
top = this.top,
|
|
97
|
+
right = this.right,
|
|
98
|
+
bottom = this.bottom
|
|
99
|
+
}) {
|
|
100
|
+
return new Rect(left, top, right, bottom);
|
|
101
|
+
}
|
|
102
|
+
static fromLTRB(left, top, right, bottom) {
|
|
103
|
+
return new Rect(left, top, right, bottom);
|
|
104
|
+
}
|
|
105
|
+
static fromLWTH(left, width, top, height) {
|
|
106
|
+
return new Rect(left, top, left + width, top + height);
|
|
107
|
+
}
|
|
108
|
+
static fromPoints(startPoint, endPoint) {
|
|
109
|
+
const {
|
|
110
|
+
y: top,
|
|
111
|
+
x: left
|
|
112
|
+
} = startPoint;
|
|
113
|
+
const {
|
|
114
|
+
y: bottom,
|
|
115
|
+
x: right
|
|
116
|
+
} = endPoint;
|
|
117
|
+
return Rect.fromLTRB(left, top, right, bottom);
|
|
118
|
+
}
|
|
119
|
+
static fromDOM(dom) {
|
|
120
|
+
const {
|
|
121
|
+
top,
|
|
122
|
+
width,
|
|
123
|
+
left,
|
|
124
|
+
height
|
|
125
|
+
} = dom.getBoundingClientRect();
|
|
126
|
+
return Rect.fromLWTH(left, width, top, height);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
163
129
|
|
|
164
130
|
//# sourceMappingURL=rect.js.map
|
package/utils/rect.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_point","require","Rect","exports","left","top","right","bottom","_classCallCheck2","default","_ref","_ref2","_slicedToArray2","physicTop","physicBottom","_ref3","_ref4","physicLeft","physicRight","_top","_right","_left","_bottom","_createClass2","key","get","Math","abs","value","equals","_ref5","contains","target","isPoint","x","y","isOnTopSide","isOnBottomSide","isOnLeftSide","isOnRightSide","result","reason","intersectsWith","rect","x1","y1","w1","width","h1","height","x2","y2","w2","h2","maxX","maxY","minX","minY","generateNewRect","_ref6","_ref6$left","_ref6$top","_ref6$right","_ref6$bottom","fromLTRB","fromLWTH","fromPoints","startPoint","endPoint","fromDOM","dom","_dom$getBoundingClien","getBoundingClientRect"],"sources":["rect.ts"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\nimport { isPoint, Point } from \"./point\";\n\ntype ContainsPointReturn = {\n result: boolean;\n reason: {\n isOnTopSide: boolean;\n isOnBottomSide: boolean;\n isOnLeftSide: boolean;\n isOnRightSide: boolean;\n };\n};\n\nexport class Rect {\n private readonly _left: number;\n private readonly _top: number;\n private readonly _right: number;\n private readonly _bottom: number;\n\n constructor(left: number, top: number, right: number, bottom: number) {\n const [physicTop, physicBottom] = top <= bottom ? [top, bottom] : [bottom, top];\n\n const [physicLeft, physicRight] = left <= right ? [left, right] : [right, left];\n\n this._top = physicTop;\n this._right = physicRight;\n this._left = physicLeft;\n this._bottom = physicBottom;\n }\n\n get top(): number {\n return this._top;\n }\n\n get right(): number {\n return this._right;\n }\n\n get bottom(): number {\n return this._bottom;\n }\n\n get left(): number {\n return this._left;\n }\n\n get width(): number {\n return Math.abs(this._left - this._right);\n }\n\n get height(): number {\n return Math.abs(this._bottom - this._top);\n }\n\n public equals({ top, left, bottom, right }: Rect): boolean {\n return (\n top === this._top &&\n bottom === this._bottom &&\n left === this._left &&\n right === this._right\n );\n }\n\n public contains({ x, y }: Point): ContainsPointReturn;\n public contains({ top, left, bottom, right }: Rect): boolean;\n public contains(target: Point | Rect): boolean | ContainsPointReturn {\n if (isPoint(target)) {\n const { x, y } = target;\n\n const isOnTopSide = y < this._top;\n const isOnBottomSide = y > this._bottom;\n const isOnLeftSide = x < this._left;\n const isOnRightSide = x > this._right;\n\n const result = !isOnTopSide && !isOnBottomSide && !isOnLeftSide && !isOnRightSide;\n\n return {\n reason: {\n isOnBottomSide,\n isOnLeftSide,\n isOnRightSide,\n isOnTopSide\n },\n result\n };\n } else {\n const { top, left, bottom, right } = target;\n\n return (\n top >= this._top &&\n top <= this._bottom &&\n bottom >= this._top &&\n bottom <= this._bottom &&\n left >= this._left &&\n left <= this._right &&\n right >= this._left &&\n right <= this._right\n );\n }\n }\n\n public intersectsWith(rect: Rect): boolean {\n const { left: x1, top: y1, width: w1, height: h1 } = rect;\n const { left: x2, top: y2, width: w2, height: h2 } = this;\n const maxX = x1 + w1 >= x2 + w2 ? x1 + w1 : x2 + w2;\n const maxY = y1 + h1 >= y2 + h2 ? y1 + h1 : y2 + h2;\n const minX = x1 <= x2 ? x1 : x2;\n const minY = y1 <= y2 ? y1 : y2;\n return maxX - minX <= w1 + w2 && maxY - minY <= h1 + h2;\n }\n\n public generateNewRect({\n left = this.left,\n top = this.top,\n right = this.right,\n bottom = this.bottom\n }): Rect {\n return new Rect(left, top, right, bottom);\n }\n\n static fromLTRB(left: number, top: number, right: number, bottom: number): Rect {\n return new Rect(left, top, right, bottom);\n }\n\n static fromLWTH(left: number, width: number, top: number, height: number): Rect {\n return new Rect(left, top, left + width, top + height);\n }\n\n static fromPoints(startPoint: Point, endPoint: Point): Rect {\n const { y: top, x: left } = startPoint;\n const { y: bottom, x: right } = endPoint;\n return Rect.fromLTRB(left, top, right, bottom);\n }\n\n static fromDOM(dom: HTMLElement): Rect {\n const { top, width, left, height } = dom.getBoundingClientRect();\n return Rect.fromLWTH(left, width, top, height);\n }\n}\n"],"mappings":";;;;;;;;;;AAOA,IAAAA,MAAA,GAAAC,OAAA;AAPA;AACA;AACA;AACA;AACA;AACA;AACA;AANA,IAmBaC,IAAI,GAAAC,OAAA,CAAAD,IAAA;EAMb,SAAAA,KAAYE,IAAY,EAAEC,GAAW,EAAEC,KAAa,EAAEC,MAAc,EAAE;IAAA,IAAAC,gBAAA,CAAAC,OAAA,QAAAP,IAAA;IAClE,IAAAQ,IAAA,GAAkCL,GAAG,IAAIE,MAAM,GAAG,CAACF,GAAG,EAAEE,MAAM,CAAC,GAAG,CAACA,MAAM,EAAEF,GAAG,CAAC;MAAAM,KAAA,OAAAC,eAAA,CAAAH,OAAA,EAAAC,IAAA;MAAxEG,SAAS,GAAAF,KAAA;MAAEG,YAAY,GAAAH,KAAA;IAE9B,IAAAI,KAAA,GAAkCX,IAAI,IAAIE,KAAK,GAAG,CAACF,IAAI,EAAEE,KAAK,CAAC,GAAG,CAACA,KAAK,EAAEF,IAAI,CAAC;MAAAY,KAAA,OAAAJ,eAAA,CAAAH,OAAA,EAAAM,KAAA;MAAxEE,UAAU,GAAAD,KAAA;MAAEE,WAAW,GAAAF,KAAA;IAE9B,IAAI,CAACG,IAAI,GAAGN,SAAS;IACrB,IAAI,CAACO,MAAM,GAAGF,WAAW;IACzB,IAAI,CAACG,KAAK,GAAGJ,UAAU;IACvB,IAAI,CAACK,OAAO,GAAGR,YAAY;EAC/B;EAAC,WAAAS,aAAA,CAAAd,OAAA,EAAAP,IAAA;IAAAsB,GAAA;IAAAC,GAAA,EAED,SAAAA,IAAA,EAAkB;MACd,OAAO,IAAI,CAAC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,IAAI,CAAC+D,QAAQ,CAAC7D,IAAI,EAAE2C,KAAK,EAAE1C,GAAG,EAAE4C,MAAM,CAAC;IAClD;EAAC;AAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["isPoint","Rect","constructor","left","top","right","bottom","physicTop","physicBottom","physicLeft","physicRight","_top","_right","_left","_bottom","width","Math","abs","height","equals","contains","target","x","y","isOnTopSide","isOnBottomSide","isOnLeftSide","isOnRightSide","result","reason","intersectsWith","rect","x1","y1","w1","h1","x2","y2","w2","h2","maxX","maxY","minX","minY","generateNewRect","fromLTRB","fromLWTH","fromPoints","startPoint","endPoint","fromDOM","dom","getBoundingClientRect"],"sources":["rect.ts"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\nimport type { Point } from \"./point.js\";\nimport { isPoint } from \"./point.js\";\n\ntype ContainsPointReturn = {\n result: boolean;\n reason: {\n isOnTopSide: boolean;\n isOnBottomSide: boolean;\n isOnLeftSide: boolean;\n isOnRightSide: boolean;\n };\n};\n\nexport class Rect {\n private readonly _left: number;\n private readonly _top: number;\n private readonly _right: number;\n private readonly _bottom: number;\n\n constructor(left: number, top: number, right: number, bottom: number) {\n const [physicTop, physicBottom] = top <= bottom ? [top, bottom] : [bottom, top];\n\n const [physicLeft, physicRight] = left <= right ? [left, right] : [right, left];\n\n this._top = physicTop;\n this._right = physicRight;\n this._left = physicLeft;\n this._bottom = physicBottom;\n }\n\n get top(): number {\n return this._top;\n }\n\n get right(): number {\n return this._right;\n }\n\n get bottom(): number {\n return this._bottom;\n }\n\n get left(): number {\n return this._left;\n }\n\n get width(): number {\n return Math.abs(this._left - this._right);\n }\n\n get height(): number {\n return Math.abs(this._bottom - this._top);\n }\n\n public equals({ top, left, bottom, right }: Rect): boolean {\n return (\n top === this._top &&\n bottom === this._bottom &&\n left === this._left &&\n right === this._right\n );\n }\n\n public contains({ x, y }: Point): ContainsPointReturn;\n public contains({ top, left, bottom, right }: Rect): boolean;\n public contains(target: Point | Rect): boolean | ContainsPointReturn {\n if (isPoint(target)) {\n const { x, y } = target;\n\n const isOnTopSide = y < this._top;\n const isOnBottomSide = y > this._bottom;\n const isOnLeftSide = x < this._left;\n const isOnRightSide = x > this._right;\n\n const result = !isOnTopSide && !isOnBottomSide && !isOnLeftSide && !isOnRightSide;\n\n return {\n reason: {\n isOnBottomSide,\n isOnLeftSide,\n isOnRightSide,\n isOnTopSide\n },\n result\n };\n } else {\n const { top, left, bottom, right } = target;\n\n return (\n top >= this._top &&\n top <= this._bottom &&\n bottom >= this._top &&\n bottom <= this._bottom &&\n left >= this._left &&\n left <= this._right &&\n right >= this._left &&\n right <= this._right\n );\n }\n }\n\n public intersectsWith(rect: Rect): boolean {\n const { left: x1, top: y1, width: w1, height: h1 } = rect;\n const { left: x2, top: y2, width: w2, height: h2 } = this;\n const maxX = x1 + w1 >= x2 + w2 ? x1 + w1 : x2 + w2;\n const maxY = y1 + h1 >= y2 + h2 ? y1 + h1 : y2 + h2;\n const minX = x1 <= x2 ? x1 : x2;\n const minY = y1 <= y2 ? y1 : y2;\n return maxX - minX <= w1 + w2 && maxY - minY <= h1 + h2;\n }\n\n public generateNewRect({\n left = this.left,\n top = this.top,\n right = this.right,\n bottom = this.bottom\n }): Rect {\n return new Rect(left, top, right, bottom);\n }\n\n static fromLTRB(left: number, top: number, right: number, bottom: number): Rect {\n return new Rect(left, top, right, bottom);\n }\n\n static fromLWTH(left: number, width: number, top: number, height: number): Rect {\n return new Rect(left, top, left + width, top + height);\n }\n\n static fromPoints(startPoint: Point, endPoint: Point): Rect {\n const { y: top, x: left } = startPoint;\n const { y: bottom, x: right } = endPoint;\n return Rect.fromLTRB(left, top, right, bottom);\n }\n\n static fromDOM(dom: HTMLElement): Rect {\n const { top, width, left, height } = dom.getBoundingClientRect();\n return Rect.fromLWTH(left, width, top, height);\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;A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AW,EAAEc,MAAc,EAAQ;IAC5E,OAAO,IAAIjB,IAAI,CAACE,IAAI,EAAEC,GAAG,EAAED,IAAI,GAAGY,KAAK,EAAEX,GAAG,GAAGc,MAAM,CAAC;EAC1D;EAEA,OAAO6B,UAAUA,CAACC,UAAiB,EAAEC,QAAe,EAAQ;IACxD,MAAM;MAAE1B,CAAC,EAAEnB,GAAG;MAAEkB,CAAC,EAAEnB;IAAK,CAAC,GAAG6C,UAAU;IACtC,MAAM;MAAEzB,CAAC,EAAEjB,MAAM;MAAEgB,CAAC,EAAEjB;IAAM,CAAC,GAAG4C,QAAQ;IACxC,OAAOhD,IAAI,CAAC4C,QAAQ,CAAC1C,IAAI,EAAEC,GAAG,EAAEC,KAAK,EAAEC,MAAM,CAAC;EAClD;EAEA,OAAO4C,OAAOA,CAACC,GAAgB,EAAQ;IACnC,MAAM;MAAE/C,GAAG;MAAEW,KAAK;MAAEZ,IAAI;MAAEe;IAAO,CAAC,GAAGiC,GAAG,CAACC,qBAAqB,CAAC,CAAC;IAChE,OAAOnD,IAAI,CAAC6C,QAAQ,CAAC3C,IAAI,EAAEY,KAAK,EAAEX,GAAG,EAAEc,MAAM,CAAC;EAClD;AACJ","ignoreList":[]}
|
package/utils/sanitizeUrl.js
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.sanitizeUrl = void 0;
|
|
7
|
-
var _isAnchorLink = require("./isAnchorLink");
|
|
8
1
|
/**
|
|
9
2
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
10
3
|
*
|
|
@@ -12,21 +5,21 @@ var _isAnchorLink = require("./isAnchorLink");
|
|
|
12
5
|
* LICENSE file in the root directory of this source tree.
|
|
13
6
|
*
|
|
14
7
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
import { isAnchorLink } from "./isAnchorLink.js";
|
|
9
|
+
export const sanitizeUrl = url => {
|
|
17
10
|
/** A pattern that matches safe URLs. */
|
|
18
|
-
|
|
11
|
+
const SAFE_URL_PATTERN = /^(?:(?:https?|mailto|ftp|tel|file|sms):|[^&:/?#]*(?:[/?#]|$))/gi;
|
|
19
12
|
|
|
20
13
|
/** A pattern that matches safe data URLs. */
|
|
21
|
-
|
|
14
|
+
const DATA_URL_PATTERN = /^data:(?:image\/(?:bmp|gif|jpeg|jpg|png|tiff|webp)|video\/(?:mpeg|mp4|ogg|webm)|audio\/(?:mp3|oga|ogg|opus));base64,[a-z0-9+/]+=*$/i;
|
|
22
15
|
url = String(url).trim();
|
|
23
|
-
if (
|
|
16
|
+
if (isAnchorLink(url)) {
|
|
24
17
|
return url;
|
|
25
18
|
}
|
|
26
19
|
if (url.match(SAFE_URL_PATTERN) || url.match(DATA_URL_PATTERN)) {
|
|
27
20
|
return url;
|
|
28
21
|
}
|
|
29
|
-
return
|
|
22
|
+
return `https://`;
|
|
30
23
|
};
|
|
31
24
|
|
|
32
25
|
//# sourceMappingURL=sanitizeUrl.js.map
|
package/utils/sanitizeUrl.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["isAnchorLink","sanitizeUrl","url","SAFE_URL_PATTERN","DATA_URL_PATTERN","String","trim","match"],"sources":["sanitizeUrl.ts"],"sourcesContent":["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\nimport { isAnchorLink } from \"~/utils/isAnchorLink.js\";\n\nexport const sanitizeUrl = (url: string): string => {\n /** A pattern that matches safe URLs. */\n const SAFE_URL_PATTERN = /^(?:(?:https?|mailto|ftp|tel|file|sms):|[^&:/?#]*(?:[/?#]|$))/gi;\n\n /** A pattern that matches safe data URLs. */\n const DATA_URL_PATTERN =\n /^data:(?:image\\/(?:bmp|gif|jpeg|jpg|png|tiff|webp)|video\\/(?:mpeg|mp4|ogg|webm)|audio\\/(?:mp3|oga|ogg|opus));base64,[a-z0-9+/]+=*$/i;\n\n url = String(url).trim();\n\n if (isAnchorLink(url)) {\n return url;\n }\n\n if (url.match(SAFE_URL_PATTERN) || url.match(DATA_URL_PATTERN)) {\n return url;\n }\n\n return `https://`;\n};\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,YAAY;AAErB,OAAO,MAAMC,WAAW,GAAIC,GAAW,IAAa;EAChD;EACA,MAAMC,gBAAgB,GAAG,iEAAiE;;EAE1F;EACA,MAAMC,gBAAgB,GAClB,qIAAqI;EAEzIF,GAAG,GAAGG,MAAM,CAACH,GAAG,CAAC,CAACI,IAAI,CAAC,CAAC;EAExB,IAAIN,YAAY,CAACE,GAAG,CAAC,EAAE;IACnB,OAAOA,GAAG;EACd;EAEA,IAAIA,GAAG,CAACK,KAAK,CAACJ,gBAAgB,CAAC,IAAID,GAAG,CAACK,KAAK,CAACH,gBAAgB,CAAC,EAAE;IAC5D,OAAOF,GAAG;EACd;EAEA,OAAO,UAAU;AACrB,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function setFloatingElemPosition(basePosition:
|
|
1
|
+
export declare function setFloatingElemPosition(basePosition: Range | null, elementToPosition: HTMLElement): void;
|