@ckeditor/ckeditor5-minimap 47.6.1 → 48.0.0-alpha.1

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.
@@ -1,149 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- /**
6
- * @module minimap/minimapview
7
- */
8
- import { View } from 'ckeditor5/src/ui.js';
9
- import { Rect } from 'ckeditor5/src/utils.js';
10
- import { MinimapIframeView } from './minimapiframeview.js';
11
- import { MinimapPositionTrackerView } from './minimappositiontrackerview.js';
12
- /**
13
- * The main view of the minimap. It renders the original content but scaled down with a tracker element
14
- * visualizing the subset of the content visible to the user and allowing interactions (scrolling, dragging).
15
- *
16
- * @internal
17
- */
18
- export class MinimapView extends View {
19
- /**
20
- * An instance of the tracker view displayed over the minimap.
21
- */
22
- _positionTrackerView;
23
- /**
24
- * The scale ratio of the minimap relative to the original editing DOM root with the content.
25
- */
26
- _scaleRatio;
27
- /**
28
- * An instance of the iframe view that hosts the minimap.
29
- */
30
- _minimapIframeView;
31
- /**
32
- * Creates an instance of the minimap view.
33
- */
34
- constructor({ locale, scaleRatio, pageStyles, extraClasses, useSimplePreview, domRootClone }) {
35
- super(locale);
36
- const bind = this.bindTemplate;
37
- this._positionTrackerView = new MinimapPositionTrackerView(locale);
38
- this._positionTrackerView.delegate('drag').to(this);
39
- this._scaleRatio = scaleRatio;
40
- this._minimapIframeView = new MinimapIframeView(locale, {
41
- useSimplePreview,
42
- pageStyles,
43
- extraClasses,
44
- scaleRatio,
45
- domRootClone
46
- });
47
- this.setTemplate({
48
- tag: 'div',
49
- attributes: {
50
- class: [
51
- 'ck',
52
- 'ck-minimap'
53
- ]
54
- },
55
- children: [
56
- this._positionTrackerView
57
- ],
58
- on: {
59
- click: bind.to(this._handleMinimapClick.bind(this)),
60
- wheel: bind.to(this._handleMinimapMouseWheel.bind(this))
61
- }
62
- });
63
- }
64
- /**
65
- * @inheritDoc
66
- */
67
- destroy() {
68
- this._minimapIframeView.destroy();
69
- super.destroy();
70
- }
71
- /**
72
- * Returns the DOM {@link module:utils/dom/rect~Rect} height of the minimap.
73
- */
74
- get height() {
75
- return new Rect(this.element).height;
76
- }
77
- /**
78
- * Returns the number of available space (pixels) the position tracker (visible subset of the content) can use to scroll vertically.
79
- */
80
- get scrollHeight() {
81
- return Math.max(0, Math.min(this.height, this._minimapIframeView.height) - this._positionTrackerView.height);
82
- }
83
- /**
84
- * @inheritDoc
85
- */
86
- render() {
87
- super.render();
88
- this._minimapIframeView.render();
89
- this.element.appendChild(this._minimapIframeView.element);
90
- }
91
- /**
92
- * Sets the new height of the minimap (in px) to respond to the changes in the original editing DOM root.
93
- *
94
- * **Note**:The provided value should be the `offsetHeight` of the original editing DOM root.
95
- */
96
- setContentHeight(newHeight) {
97
- this._minimapIframeView.setHeight(newHeight * this._scaleRatio);
98
- }
99
- /**
100
- * Sets the minimap scroll progress.
101
- *
102
- * The minimap scroll progress is linked to the original editing DOM root and its scrollable container (ancestor).
103
- * Changing the progress will alter the vertical position of the minimap (and its position tracker) and give the user an accurate
104
- * overview of the visible document.
105
- *
106
- * **Note**: The value should be between 0 and 1. 0 when the DOM root has not been scrolled, 1 when the
107
- * scrolling has reached the end.
108
- */
109
- setScrollProgress(newScrollProgress) {
110
- const iframeView = this._minimapIframeView;
111
- const positionTrackerView = this._positionTrackerView;
112
- // The scrolling should end when the bottom edge of the iframe touches the bottom edge of the minimap.
113
- if (iframeView.height < this.height) {
114
- iframeView.setTopOffset(0);
115
- positionTrackerView.setTopOffset((iframeView.height - positionTrackerView.height) * newScrollProgress);
116
- }
117
- else {
118
- const totalOffset = iframeView.height - this.height;
119
- iframeView.setTopOffset(-totalOffset * newScrollProgress);
120
- positionTrackerView.setTopOffset((this.height - positionTrackerView.height) * newScrollProgress);
121
- }
122
- positionTrackerView.setScrollProgress(Math.round(newScrollProgress * 100));
123
- }
124
- /**
125
- * Sets the new height of the tracker (in px) to visualize the subset of the content visible to the user.
126
- */
127
- setPositionTrackerHeight(trackerHeight) {
128
- this._positionTrackerView.setHeight(trackerHeight * this._scaleRatio);
129
- }
130
- /**
131
- * @param data DOM event data
132
- */
133
- _handleMinimapClick(data) {
134
- const positionTrackerView = this._positionTrackerView;
135
- if (data.target === positionTrackerView.element) {
136
- return;
137
- }
138
- const trackerViewRect = new Rect(positionTrackerView.element);
139
- const diff = data.clientY - trackerViewRect.top - trackerViewRect.height / 2;
140
- const percentage = diff / this._minimapIframeView.height;
141
- this.fire('click', percentage);
142
- }
143
- /**
144
- * @param data DOM event data
145
- */
146
- _handleMinimapMouseWheel(data) {
147
- this.fire('drag', data.deltaY * this._scaleRatio);
148
- }
149
- }
package/src/utils.js DELETED
@@ -1,96 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- /**
6
- * @module minimap/utils
7
- */
8
- import { Rect, global } from 'ckeditor5/src/utils.js';
9
- import { ViewDomConverter, ViewRenderer } from 'ckeditor5/src/engine.js';
10
- /**
11
- * Clones the editing view DOM root by using a dedicated pair of {@link module:engine/view/renderer~ViewRenderer} and
12
- * {@link module:engine/view/domconverter~ViewDomConverter}. The DOM root clone updates incrementally to stay in sync with the
13
- * source root.
14
- *
15
- * @internal
16
- * @param editor The editor instance the original editing root belongs to.
17
- * @param rootName The name of the root to clone.
18
- * @returns The editing root DOM clone element.
19
- */
20
- export function cloneEditingViewDomRoot(editor, rootName) {
21
- const viewDocument = editor.editing.view.document;
22
- const viewRoot = viewDocument.getRoot(rootName);
23
- const domConverter = new ViewDomConverter(viewDocument);
24
- const renderer = new ViewRenderer(domConverter, viewDocument.selection);
25
- const domRootClone = editor.editing.view.getDomRoot().cloneNode();
26
- domConverter.bindElements(domRootClone, viewRoot);
27
- renderer.markToSync('children', viewRoot);
28
- renderer.markToSync('attributes', viewRoot);
29
- viewRoot.on('change:children', (evt, node) => renderer.markToSync('children', node));
30
- viewRoot.on('change:attributes', (evt, node) => renderer.markToSync('attributes', node));
31
- viewRoot.on('change:text', (evt, node) => renderer.markToSync('text', node));
32
- renderer.render();
33
- editor.editing.view.on('render', () => renderer.render());
34
- // TODO: Cleanup after destruction.
35
- editor.on('destroy', () => {
36
- domConverter.unbindDomElement(domRootClone);
37
- });
38
- return domRootClone;
39
- }
40
- /**
41
- * Harvests all web page styles, for instance, to allow re-using them in an `<iframe>` preserving the look of the content.
42
- *
43
- * The returned data format is as follows:
44
- *
45
- * ```ts
46
- * [
47
- * 'p { color: red; ... } h2 { font-size: 2em; ... } ...',
48
- * '.spacing { padding: 1em; ... }; ...',
49
- * '...',
50
- * { href: 'http://link.to.external.stylesheet' },
51
- * { href: '...' }
52
- * ]
53
- * ```
54
- *
55
- * **Note**: For stylesheets with `href` different than window origin, an object is returned because
56
- * accessing rules of these styles may cause CORS errors (depending on the configuration of the web page).
57
- *
58
- * @internal
59
- */
60
- export function getPageStyles() {
61
- return Array.from(global.document.styleSheets)
62
- .map(styleSheet => {
63
- // CORS
64
- if (styleSheet.href && !styleSheet.href.startsWith(global.window.location.origin)) {
65
- return { href: styleSheet.href };
66
- }
67
- return Array.from(styleSheet.cssRules)
68
- .filter(rule => !(rule instanceof CSSMediaRule))
69
- .map(rule => rule.cssText)
70
- .join(' \n');
71
- });
72
- }
73
- /**
74
- * Gets dimensions rectangle according to passed DOM element. Returns whole window's size for `body` element.
75
- *
76
- * @internal
77
- */
78
- export function getDomElementRect(domElement) {
79
- return new Rect(domElement === global.document.body ? global.window : domElement);
80
- }
81
- /**
82
- * Gets client height according to passed DOM element. Returns window's height for `body` element.
83
- *
84
- * @internal
85
- */
86
- export function getClientHeight(domElement) {
87
- return domElement === global.document.body ? global.window.innerHeight : domElement.clientHeight;
88
- }
89
- /**
90
- * Returns the DOM element itself if it's not a `body` element, whole window otherwise.
91
- *
92
- * @internal
93
- */
94
- export function getScrollable(domElement) {
95
- return domElement === global.document.body ? global.window : domElement;
96
- }
package/theme/minimap.css DELETED
@@ -1,80 +0,0 @@
1
- /*
2
- * Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
-
6
- :root {
7
- --ck-color-minimap-tracker-background: 208, 0%, 51%;
8
- --ck-color-minimap-iframe-outline: hsl(0deg 0% 75%);
9
- --ck-color-minimap-iframe-shadow: hsl(0deg 0% 0% / 11%);
10
- --ck-color-minimap-progress-background: hsl(0,0%,40%);
11
- }
12
-
13
- .ck.ck-minimap {
14
- position: absolute;
15
- user-select: none;
16
- background: var(--ck-color-base-background);
17
-
18
- &,
19
- & iframe {
20
- width: 100%;
21
- height: 100%;
22
- }
23
-
24
- & iframe {
25
- border: 0;
26
- pointer-events: none;
27
- position: relative;
28
- outline: 1px solid var(--ck-color-minimap-iframe-outline);
29
- box-shadow: 0 2px 5px var(--ck-color-minimap-iframe-shadow);
30
- margin: 0;
31
- }
32
-
33
- & .ck.ck-minimap__position-tracker {
34
- position: absolute;
35
- width: 100%;
36
- top: 0;
37
- background: hsla( var(--ck-color-minimap-tracker-background), .2 );
38
- z-index: 1;
39
- transition: background 100ms ease-in-out;
40
-
41
-
42
- @media (prefers-reduced-motion: reduce) {
43
- transition: none;
44
- }
45
-
46
- &:hover {
47
- background:hsla( var(--ck-color-minimap-tracker-background), .3 );
48
- }
49
-
50
- &.ck-minimap__position-tracker_dragging,
51
- &.ck-minimap__position-tracker_dragging:hover {
52
- background:hsla( var(--ck-color-minimap-tracker-background), .4 );
53
-
54
- &::after {
55
- opacity: 1;
56
- }
57
- }
58
-
59
- &::after {
60
- content: attr(data-progress) "%";
61
- position: absolute;
62
- top: 5px;
63
- right: 5px;
64
- background: var(--ck-color-minimap-progress-background);
65
- color: var(--ck-color-base-background);
66
- border: 1px solid var(--ck-color-base-background);
67
- padding: 2px 4px;
68
- font-size: 10px;
69
- border-radius: 3px;
70
- opacity: 0;
71
- transition: opacity 100ms ease-in-out;
72
-
73
-
74
- @media (prefers-reduced-motion: reduce) {
75
- transition: none;
76
- }
77
- }
78
- }
79
- }
80
-
File without changes
File without changes
File without changes