@plannotator/web-highlighter 0.8.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/.cursor/environment.json +6 -0
- package/.eslintrc.js +250 -0
- package/.prettierrc +9 -0
- package/.travis.yml +17 -0
- package/CHANGELOG.md +220 -0
- package/LICENSE +21 -0
- package/README.md +371 -0
- package/README.zh_CN.md +367 -0
- package/config/base.config.js +25 -0
- package/config/base.example.config.js +38 -0
- package/config/paths.js +22 -0
- package/config/server.config.js +17 -0
- package/config/webpack.config.dev.js +18 -0
- package/config/webpack.config.example.js +20 -0
- package/config/webpack.config.prod.js +28 -0
- package/dist/data/cache.d.ts +13 -0
- package/dist/index.d.ts +58 -0
- package/dist/model/range/dom.d.ts +6 -0
- package/dist/model/range/index.d.ts +20 -0
- package/dist/model/range/selection.d.ts +14 -0
- package/dist/model/source/dom.d.ts +23 -0
- package/dist/model/source/index.d.ts +18 -0
- package/dist/painter/dom.d.ts +22 -0
- package/dist/painter/index.d.ts +19 -0
- package/dist/painter/style.d.ts +1 -0
- package/dist/types/index.d.ts +102 -0
- package/dist/util/camel.d.ts +5 -0
- package/dist/util/const.d.ts +41 -0
- package/dist/util/deferred.d.ts +9 -0
- package/dist/util/dom.d.ts +32 -0
- package/dist/util/event.emitter.d.ts +13 -0
- package/dist/util/hook.d.ts +15 -0
- package/dist/util/interaction.d.ts +6 -0
- package/dist/util/is.mobile.d.ts +5 -0
- package/dist/util/tool.d.ts +4 -0
- package/dist/util/uuid.d.ts +4 -0
- package/dist/web-highlighter.min.js +3 -0
- package/dist/web-highlighter.min.js.map +1 -0
- package/docs/ADVANCE.md +113 -0
- package/docs/ADVANCE.zh_CN.md +111 -0
- package/docs/img/create-flow.jpg +0 -0
- package/docs/img/create-flow.zh_CN.jpg +0 -0
- package/docs/img/logo.png +0 -0
- package/docs/img/remove-flow.jpg +0 -0
- package/docs/img/remove-flow.zh_CN.jpg +0 -0
- package/docs/img/sample.gif +0 -0
- package/example/index.css +2 -0
- package/example/index.js +214 -0
- package/example/local.store.js +72 -0
- package/example/my.css +119 -0
- package/example/tpl.html +59 -0
- package/package.json +103 -0
- package/script/build.js +17 -0
- package/script/convet-md.js +25 -0
- package/script/dev.js +22 -0
- package/src/data/cache.ts +57 -0
- package/src/index.ts +285 -0
- package/src/model/range/dom.ts +94 -0
- package/src/model/range/index.ts +88 -0
- package/src/model/range/selection.ts +55 -0
- package/src/model/source/dom.ts +66 -0
- package/src/model/source/index.ts +54 -0
- package/src/painter/dom.ts +345 -0
- package/src/painter/index.ts +199 -0
- package/src/painter/style.ts +21 -0
- package/src/types/index.ts +118 -0
- package/src/util/camel.ts +6 -0
- package/src/util/const.ts +54 -0
- package/src/util/deferred.ts +37 -0
- package/src/util/dom.ts +155 -0
- package/src/util/event.emitter.ts +45 -0
- package/src/util/hook.ts +52 -0
- package/src/util/interaction.ts +20 -0
- package/src/util/is.mobile.ts +7 -0
- package/src/util/tool.ts +14 -0
- package/src/util/uuid.ts +10 -0
- package/test/api.spec.ts +555 -0
- package/test/event.spec.ts +284 -0
- package/test/fixtures/broken.json +32 -0
- package/test/fixtures/index.html +11 -0
- package/test/fixtures/source.json +47 -0
- package/test/hook.spec.ts +244 -0
- package/test/integrate.spec.ts +48 -0
- package/test/mobile.spec.ts +87 -0
- package/test/option.spec.ts +212 -0
- package/test/util.spec.ts +244 -0
- package/test-newlines.html +226 -0
- package/tsconfig.json +23 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { DomNode } from '@src//types';
|
|
2
|
+
import type HighlightSource from './index';
|
|
3
|
+
/**
|
|
4
|
+
* Because of supporting highlighting a same area (range overlapping),
|
|
5
|
+
* Highlighter will calculate which text-node and how much offset it actually be,
|
|
6
|
+
* based on the origin website dom node and the text offset.
|
|
7
|
+
*
|
|
8
|
+
* @param {Node} $parent element node in the origin website dom tree
|
|
9
|
+
* @param {number} offset text offset in the origin website dom tree
|
|
10
|
+
* @return {DomNode} DOM a dom info object
|
|
11
|
+
*/
|
|
12
|
+
export declare const getTextChildByOffset: ($parent: Node, offset: number) => DomNode;
|
|
13
|
+
/**
|
|
14
|
+
* get start and end parent element from meta info
|
|
15
|
+
*
|
|
16
|
+
* @param {HighlightSource} hs
|
|
17
|
+
* @param {HTMLElement | Document} $root root element, default document
|
|
18
|
+
* @return {Object}
|
|
19
|
+
*/
|
|
20
|
+
export declare const queryElementNode: (hs: HighlightSource, $root: Document | HTMLElement) => {
|
|
21
|
+
start: Node;
|
|
22
|
+
end: Node;
|
|
23
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HighlightSource Class (HSource)
|
|
3
|
+
* This Object can be deSerialized to HRange.
|
|
4
|
+
* Also it has the ability for persistence.
|
|
5
|
+
*/
|
|
6
|
+
import type { DomMeta, HookMap } from '../../types';
|
|
7
|
+
import HighlightRange from '../range/index';
|
|
8
|
+
declare class HighlightSource {
|
|
9
|
+
startMeta: DomMeta;
|
|
10
|
+
endMeta: DomMeta;
|
|
11
|
+
text: string;
|
|
12
|
+
id: string;
|
|
13
|
+
extra?: unknown;
|
|
14
|
+
__isHighlightSource: unknown;
|
|
15
|
+
constructor(startMeta: DomMeta, endMeta: DomMeta, text: string, id: string, extra?: unknown);
|
|
16
|
+
deSerialize($root: Document | HTMLElement, hooks: HookMap): HighlightRange;
|
|
17
|
+
}
|
|
18
|
+
export default HighlightSource;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type HighlightRange from '../model/range';
|
|
2
|
+
import type { SelectedNode, DomNode } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* get all the dom nodes between the start and end node
|
|
5
|
+
*/
|
|
6
|
+
export declare const getSelectedNodes: ($root: Document | HTMLElement, start: DomNode, end: DomNode, exceptSelectors: string[]) => SelectedNode[];
|
|
7
|
+
/**
|
|
8
|
+
* wrap a dom node with highlight wrapper
|
|
9
|
+
*
|
|
10
|
+
* Because of supporting the highlight-overlapping,
|
|
11
|
+
* Highlighter can't just wrap all nodes in a simple way.
|
|
12
|
+
* There are three types:
|
|
13
|
+
* - wrapping a whole new node (without any wrapper)
|
|
14
|
+
* - wrapping part of the node
|
|
15
|
+
* - wrapping the whole wrapped node
|
|
16
|
+
*/
|
|
17
|
+
export declare const wrapHighlight: (selected: SelectedNode, range: HighlightRange, className: string[] | string, wrapTag: string) => HTMLElement;
|
|
18
|
+
/**
|
|
19
|
+
* merge the adjacent text nodes
|
|
20
|
+
* .normalize() API has some bugs in IE11
|
|
21
|
+
*/
|
|
22
|
+
export declare const normalizeSiblingText: ($s: Node, isNext?: boolean) => void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Painter object is designed for some painting work about higlighting,
|
|
3
|
+
* including rendering, cleaning...
|
|
4
|
+
* No need to instantiate repeatly. A Highlighter instance will bind a Painter instance.
|
|
5
|
+
*/
|
|
6
|
+
import type HighlightRange from '../model/range';
|
|
7
|
+
import type { PainterOptions, HookMap } from '../types';
|
|
8
|
+
import HighlightSource from '../model/source';
|
|
9
|
+
export default class Painter {
|
|
10
|
+
options: PainterOptions;
|
|
11
|
+
$style: HTMLStyleElement;
|
|
12
|
+
styleId: string;
|
|
13
|
+
hooks: HookMap;
|
|
14
|
+
constructor(options: PainterOptions, hooks: HookMap);
|
|
15
|
+
highlightRange(range: HighlightRange): HTMLElement[];
|
|
16
|
+
highlightSource(sources: HighlightSource | HighlightSource[]): HighlightSource[];
|
|
17
|
+
removeHighlight(id: string): boolean;
|
|
18
|
+
removeAllHighlight(): void;
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const initDefaultStylesheet: () => HTMLStyleElement;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type Hook from '../util/hook';
|
|
2
|
+
export declare type RootElement = Document | HTMLElement;
|
|
3
|
+
export interface HighlighterOptions {
|
|
4
|
+
$root?: RootElement;
|
|
5
|
+
exceptSelectors?: string[];
|
|
6
|
+
wrapTag?: string;
|
|
7
|
+
verbose?: boolean;
|
|
8
|
+
style?: {
|
|
9
|
+
className?: string[] | string;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export interface PainterOptions {
|
|
13
|
+
$root: RootElement;
|
|
14
|
+
wrapTag: string;
|
|
15
|
+
className: string[] | string;
|
|
16
|
+
exceptSelectors: string[];
|
|
17
|
+
}
|
|
18
|
+
export declare enum SplitType {
|
|
19
|
+
none = "none",
|
|
20
|
+
head = "head",
|
|
21
|
+
tail = "tail",
|
|
22
|
+
both = "both"
|
|
23
|
+
}
|
|
24
|
+
export declare enum ERROR {
|
|
25
|
+
DOM_TYPE_ERROR = "[DOM] Receive wrong node type.",
|
|
26
|
+
DOM_SELECTION_EMPTY = "[DOM] The selection contains no dom node, may be you except them.",
|
|
27
|
+
RANGE_INVALID = "[RANGE] Got invalid dom range, can't convert to a valid highlight range.",
|
|
28
|
+
RANGE_NODE_INVALID = "[RANGE] Start or end node isn't a text node, it may occur an error.",
|
|
29
|
+
DB_ID_DUPLICATE_ERROR = "[STORE] Unique id conflict.",
|
|
30
|
+
CACHE_SET_ERROR = "[CACHE] Cache.data can't be set manually, please use .save().",
|
|
31
|
+
SOURCE_TYPE_ERROR = "[SOURCE] Object isn't a highlight source instance.",
|
|
32
|
+
HIGHLIGHT_RANGE_FROZEN = "[HIGHLIGHT_RANGE] A highlight range must be frozen before render.",
|
|
33
|
+
HIGHLIGHT_SOURCE_RECREATE = "[HIGHLIGHT_SOURCE] Recreate highlights from sources error.",
|
|
34
|
+
HIGHLIGHT_SOURCE_NONE_RENDER = "[HIGHLIGHT_SOURCE] This highlight source isn't rendered. May be the exception skips it or the dom structure has changed."
|
|
35
|
+
}
|
|
36
|
+
export declare enum EventType {
|
|
37
|
+
CREATE = "selection:create",
|
|
38
|
+
REMOVE = "selection:remove",
|
|
39
|
+
MODIFY = "selection:modify",
|
|
40
|
+
HOVER = "selection:hover",
|
|
41
|
+
HOVER_OUT = "selection:hover-out",
|
|
42
|
+
CLICK = "selection:click"
|
|
43
|
+
}
|
|
44
|
+
export declare enum CreateFrom {
|
|
45
|
+
STORE = "from-store",
|
|
46
|
+
INPUT = "from-input"
|
|
47
|
+
}
|
|
48
|
+
export declare enum SelectedNodeType {
|
|
49
|
+
text = "text",
|
|
50
|
+
span = "span"
|
|
51
|
+
}
|
|
52
|
+
export interface SelectedNode {
|
|
53
|
+
$node: Node | Text;
|
|
54
|
+
type: SelectedNodeType;
|
|
55
|
+
splitType: SplitType;
|
|
56
|
+
}
|
|
57
|
+
export interface DomMeta {
|
|
58
|
+
parentTagName: string;
|
|
59
|
+
parentIndex: number;
|
|
60
|
+
textOffset: number;
|
|
61
|
+
extra?: unknown;
|
|
62
|
+
}
|
|
63
|
+
export interface DomNode {
|
|
64
|
+
$node: Node;
|
|
65
|
+
offset: number;
|
|
66
|
+
}
|
|
67
|
+
export interface HighlightPosition {
|
|
68
|
+
start: {
|
|
69
|
+
top: number;
|
|
70
|
+
left: number;
|
|
71
|
+
};
|
|
72
|
+
end: {
|
|
73
|
+
top: number;
|
|
74
|
+
left: number;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
export interface HookMap {
|
|
78
|
+
Render: {
|
|
79
|
+
UUID: Hook<string>;
|
|
80
|
+
SelectedNodes: Hook<SelectedNode[]>;
|
|
81
|
+
WrapNode: Hook<HTMLElement>;
|
|
82
|
+
};
|
|
83
|
+
Serialize: {
|
|
84
|
+
Restore: Hook<DomNode[]>;
|
|
85
|
+
RecordInfo: Hook<string>;
|
|
86
|
+
};
|
|
87
|
+
Remove: {
|
|
88
|
+
UpdateNodes: Hook;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
export declare enum UserInputEvent {
|
|
92
|
+
touchend = "touchend",
|
|
93
|
+
mouseup = "mouseup",
|
|
94
|
+
touchstart = "touchstart",
|
|
95
|
+
click = "click",
|
|
96
|
+
mouseover = "mouseover"
|
|
97
|
+
}
|
|
98
|
+
export interface IInteraction {
|
|
99
|
+
PointerEnd: UserInputEvent;
|
|
100
|
+
PointerTap: UserInputEvent;
|
|
101
|
+
PointerOver: UserInputEvent;
|
|
102
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* all constants
|
|
3
|
+
* cSpell:ignore mengshou
|
|
4
|
+
*/
|
|
5
|
+
import type HighlightSource from '../model/source';
|
|
6
|
+
import type { ERROR } from '../types';
|
|
7
|
+
import EventEmitter from './event.emitter';
|
|
8
|
+
export declare const ID_DIVISION = ";";
|
|
9
|
+
export declare const LOCAL_STORE_KEY = "highlight-mengshou";
|
|
10
|
+
export declare const STYLESHEET_ID = "highlight-mengshou-style";
|
|
11
|
+
export declare const DATASET_IDENTIFIER = "highlight-id";
|
|
12
|
+
export declare const DATASET_IDENTIFIER_EXTRA = "highlight-id-extra";
|
|
13
|
+
export declare const DATASET_SPLIT_TYPE = "highlight-split-type";
|
|
14
|
+
export declare const CAMEL_DATASET_IDENTIFIER: string;
|
|
15
|
+
export declare const CAMEL_DATASET_IDENTIFIER_EXTRA: string;
|
|
16
|
+
export declare const CAMEL_DATASET_SPLIT_TYPE: string;
|
|
17
|
+
export declare const getDefaultOptions: () => {
|
|
18
|
+
$root: HTMLElement | Document;
|
|
19
|
+
exceptSelectors: any;
|
|
20
|
+
wrapTag: string;
|
|
21
|
+
verbose: boolean;
|
|
22
|
+
style: {
|
|
23
|
+
className: string;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export declare const getStylesheet: () => string;
|
|
27
|
+
export declare const ROOT_IDX = -2;
|
|
28
|
+
export declare const UNKNOWN_IDX = -1;
|
|
29
|
+
export declare const INTERNAL_ERROR_EVENT = "error";
|
|
30
|
+
interface EventHandlerMap {
|
|
31
|
+
[key: string]: (...args: any[]) => void;
|
|
32
|
+
error: (data: {
|
|
33
|
+
type: ERROR;
|
|
34
|
+
detail?: HighlightSource;
|
|
35
|
+
error?: any;
|
|
36
|
+
}) => void;
|
|
37
|
+
}
|
|
38
|
+
declare class ErrorEventEmitter extends EventEmitter<EventHandlerMap> {
|
|
39
|
+
}
|
|
40
|
+
export declare const eventEmitter: ErrorEventEmitter;
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
interface Deferred<T> {
|
|
2
|
+
promise: Promise<T>;
|
|
3
|
+
resolve: (args: T) => unknown;
|
|
4
|
+
reject: (e?: unknown) => unknown;
|
|
5
|
+
}
|
|
6
|
+
export default function getDeferred<T>(): Deferred<T>;
|
|
7
|
+
export declare const resolve: <T>(data: T) => Promise<T>;
|
|
8
|
+
export declare const reject: <T>(data: T) => Promise<T>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { RootElement } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* whether a wrapper node
|
|
4
|
+
*/
|
|
5
|
+
export declare const isHighlightWrapNode: ($node: HTMLElement) => boolean;
|
|
6
|
+
/**
|
|
7
|
+
* get highlight id by a node
|
|
8
|
+
*/
|
|
9
|
+
export declare const getHighlightId: ($node: HTMLElement, $root: RootElement) => string;
|
|
10
|
+
/**
|
|
11
|
+
* get extra highlight id by a node
|
|
12
|
+
*/
|
|
13
|
+
export declare const getExtraHighlightId: ($node: HTMLElement, $root: RootElement) => string[];
|
|
14
|
+
/**
|
|
15
|
+
* get all highlight wrapping nodes nodes from a root node
|
|
16
|
+
*/
|
|
17
|
+
export declare const getHighlightsByRoot: ($roots: RootElement | RootElement[], wrapTag: string) => HTMLElement[];
|
|
18
|
+
/**
|
|
19
|
+
* get all highlight wrapping nodes by highlight id from a root node
|
|
20
|
+
*/
|
|
21
|
+
export declare const getHighlightById: ($root: RootElement, id: string, wrapTag: string) => HTMLElement[];
|
|
22
|
+
export declare const forEach: ($nodes: NodeList, cb: (n: Node, idx: number, s: NodeList) => void) => void;
|
|
23
|
+
export declare const removeEventListener: ($el: RootElement, evt: string, fn: EventListenerOrEventListenerObject) => void;
|
|
24
|
+
/**
|
|
25
|
+
* maybe be need some polyfill methods later
|
|
26
|
+
* provide unified dom methods for compatibility
|
|
27
|
+
*/
|
|
28
|
+
export declare const addEventListener: ($el: RootElement, evt: string, fn: EventListenerOrEventListenerObject) => () => void;
|
|
29
|
+
export declare const addClass: ($el: HTMLElement, className: string[] | string) => void;
|
|
30
|
+
export declare const removeClass: ($el: HTMLElement, className: string) => void;
|
|
31
|
+
export declare const removeAllClass: ($el: HTMLElement) => void;
|
|
32
|
+
export declare const hasClass: ($el: HTMLElement, className: string) => boolean;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tiny event emitter
|
|
3
|
+
* modify from mitt
|
|
4
|
+
*/
|
|
5
|
+
declare type EventHandler = (...data: unknown[]) => void;
|
|
6
|
+
declare type EventMap = Record<string, EventHandler>;
|
|
7
|
+
declare class EventEmitter<U extends EventMap = EventMap> {
|
|
8
|
+
private handlersMap;
|
|
9
|
+
on<T extends keyof U>(type: T, handler: U[T]): this;
|
|
10
|
+
off<T extends keyof U>(type: T, handler: U[T]): this;
|
|
11
|
+
emit<T extends keyof U>(type: T, ...data: Parameters<U[T]>): this;
|
|
12
|
+
}
|
|
13
|
+
export default EventEmitter;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* simple hook
|
|
3
|
+
* webpack-plugin-liked api
|
|
4
|
+
*/
|
|
5
|
+
declare type HookCallback<T> = (...args: unknown[]) => T;
|
|
6
|
+
declare class Hook<T = unknown> {
|
|
7
|
+
name: string;
|
|
8
|
+
private readonly ops;
|
|
9
|
+
constructor(name?: any);
|
|
10
|
+
tap(cb: HookCallback<T>): () => void;
|
|
11
|
+
remove(cb: HookCallback<T>): void;
|
|
12
|
+
isEmpty(): boolean;
|
|
13
|
+
call(...args: unknown[]): T;
|
|
14
|
+
}
|
|
15
|
+
export default Hook;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/*! @plannotator/web-highlighter v0.8.0 https://github.com/backnotprop/web-highlighter */
|
|
2
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Highlighter=t():e.Highlighter=t()}(window,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=8)}([function(e,t,n){"use strict";var r,o=this&&this.__extends||(r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.eventEmitter=t.INTERNAL_ERROR_EVENT=t.UNKNOWN_IDX=t.ROOT_IDX=t.getStylesheet=t.getDefaultOptions=t.CAMEL_DATASET_SPLIT_TYPE=t.CAMEL_DATASET_IDENTIFIER_EXTRA=t.CAMEL_DATASET_IDENTIFIER=t.DATASET_SPLIT_TYPE=t.DATASET_IDENTIFIER_EXTRA=t.DATASET_IDENTIFIER=t.STYLESHEET_ID=t.LOCAL_STORE_KEY=t.ID_DIVISION=void 0;var a=i(n(11)),l=i(n(2));t.ID_DIVISION=";",t.LOCAL_STORE_KEY="highlight-mengshou",t.STYLESHEET_ID="highlight-mengshou-style",t.DATASET_IDENTIFIER="highlight-id",t.DATASET_IDENTIFIER_EXTRA="highlight-id-extra",t.DATASET_SPLIT_TYPE="highlight-split-type",t.CAMEL_DATASET_IDENTIFIER=a.default(t.DATASET_IDENTIFIER),t.CAMEL_DATASET_IDENTIFIER_EXTRA=a.default(t.DATASET_IDENTIFIER_EXTRA),t.CAMEL_DATASET_SPLIT_TYPE=a.default(t.DATASET_SPLIT_TYPE);t.getDefaultOptions=function(){return{$root:document||document.documentElement,exceptSelectors:null,wrapTag:"span",verbose:!1,style:{className:"highlight-mengshou-wrap"}}};t.getStylesheet=function(){return"\n ."+t.getDefaultOptions().style.className+" {\n background: #ff9;\n cursor: pointer;\n }\n ."+t.getDefaultOptions().style.className+".active {\n background: #ffb;\n }\n"},t.ROOT_IDX=-2,t.UNKNOWN_IDX=-1,t.INTERNAL_ERROR_EVENT="error";var u=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return o(t,e),t}(l.default);t.eventEmitter=new u},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.UserInputEvent=t.SelectedNodeType=t.CreateFrom=t.EventType=t.ERROR=t.SplitType=void 0,function(e){e.none="none",e.head="head",e.tail="tail",e.both="both"}(t.SplitType||(t.SplitType={})),function(e){e.DOM_TYPE_ERROR="[DOM] Receive wrong node type.",e.DOM_SELECTION_EMPTY="[DOM] The selection contains no dom node, may be you except them.",e.RANGE_INVALID="[RANGE] Got invalid dom range, can't convert to a valid highlight range.",e.RANGE_NODE_INVALID="[RANGE] Start or end node isn't a text node, it may occur an error.",e.DB_ID_DUPLICATE_ERROR="[STORE] Unique id conflict.",e.CACHE_SET_ERROR="[CACHE] Cache.data can't be set manually, please use .save().",e.SOURCE_TYPE_ERROR="[SOURCE] Object isn't a highlight source instance.",e.HIGHLIGHT_RANGE_FROZEN="[HIGHLIGHT_RANGE] A highlight range must be frozen before render.",e.HIGHLIGHT_SOURCE_RECREATE="[HIGHLIGHT_SOURCE] Recreate highlights from sources error.",e.HIGHLIGHT_SOURCE_NONE_RENDER="[HIGHLIGHT_SOURCE] This highlight source isn't rendered. May be the exception skips it or the dom structure has changed."}(t.ERROR||(t.ERROR={})),function(e){e.CREATE="selection:create",e.REMOVE="selection:remove",e.MODIFY="selection:modify",e.HOVER="selection:hover",e.HOVER_OUT="selection:hover-out",e.CLICK="selection:click"}(t.EventType||(t.EventType={})),function(e){e.STORE="from-store",e.INPUT="from-input"}(t.CreateFrom||(t.CreateFrom={})),function(e){e.text="text",e.span="span"}(t.SelectedNodeType||(t.SelectedNodeType={})),function(e){e.touchend="touchend",e.mouseup="mouseup",e.touchstart="touchstart",e.click="click",e.mouseover="mouseover"}(t.UserInputEvent||(t.UserInputEvent={}))},function(e,t,n){"use strict";var r=this&&this.__read||function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a},o=this&&this.__spread||function(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(r(arguments[t]));return e};Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(){this.handlersMap=Object.create(null)}return e.prototype.on=function(e,t){return this.handlersMap[e]||(this.handlersMap[e]=[]),this.handlersMap[e].push(t),this},e.prototype.off=function(e,t){return this.handlersMap[e]&&this.handlersMap[e].splice(this.handlersMap[e].indexOf(t)>>>0,1),this},e.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];return this.handlersMap[e]&&this.handlersMap[e].slice().forEach((function(e){e.apply(void 0,o(t))})),this},e}();t.default=i},function(e,t,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var o=r(n(5)),i=n(10),a=function(){function e(e,t,n,r,o){this.startMeta=e,this.endMeta=t,this.text=n,this.id=r,this.__isHighlightSource={},o&&(this.extra=o)}return e.prototype.deSerialize=function(e,t){var n=i.queryElementNode(this,e),r=n.start,a=n.end,l=i.getTextChildByOffset(r,this.startMeta.textOffset),u=i.getTextChildByOffset(a,this.endMeta.textOffset);if(!t.Serialize.Restore.isEmpty()){var s=t.Serialize.Restore.call(this,l,u)||[];l=s[0]||l,u=s[1]||u}return new o.default(l,u,this.text,this.id,!0)},e}();t.default=a},function(e,t,n){"use strict";var r=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")},o=this&&this.__read||function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a},i=this&&this.__spread||function(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(o(arguments[t]));return e};Object.defineProperty(t,"__esModule",{value:!0}),t.hasClass=t.removeAllClass=t.removeClass=t.addClass=t.addEventListener=t.removeEventListener=t.forEach=t.getHighlightById=t.getHighlightsByRoot=t.getExtraHighlightId=t.getHighlightId=t.isHighlightWrapNode=void 0;var a=n(0);t.isHighlightWrapNode=function(e){return!!e.dataset&&!!e.dataset[a.CAMEL_DATASET_IDENTIFIER]};var l=function(e,n){for(var r=!1,o=null;e;){if(t.isHighlightWrapNode(e)&&(o=e),e===n){r=!0;break}e=e.parentNode}return r?o:null};t.getHighlightId=function(e,t){return(e=l(e,t))?e.dataset[a.CAMEL_DATASET_IDENTIFIER]:""};t.getExtraHighlightId=function(e,t){return(e=l(e,t))?e.dataset[a.CAMEL_DATASET_IDENTIFIER_EXTRA].split(a.ID_DIVISION).filter((function(e){return e})):[]};t.getHighlightsByRoot=function(e,t){var n,o;Array.isArray(e)||(e=[e]);var i=[];try{for(var l=r(e),u=l.next();!u.done;u=l.next()){var s=u.value.querySelectorAll(t+"[data-"+a.DATASET_IDENTIFIER+"]");i.push.apply(i,s)}}catch(e){n={error:e}}finally{try{u&&!u.done&&(o=l.return)&&o.call(l)}finally{if(n)throw n.error}}return i};t.getHighlightById=function(e,t,n){var o,i,l=[],u=new RegExp("("+t+"\\"+a.ID_DIVISION+"|\\"+a.ID_DIVISION+"?"+t+"$)"),s=e.querySelectorAll(n+"[data-"+a.DATASET_IDENTIFIER+"]");try{for(var d=r(s),c=d.next();!c.done;c=d.next()){var f=c.value;if(f.dataset[a.CAMEL_DATASET_IDENTIFIER]!==t){var h=f.dataset[a.CAMEL_DATASET_IDENTIFIER_EXTRA];u.test(h)&&l.push(f)}else l.push(f)}}catch(e){o={error:e}}finally{try{c&&!c.done&&(i=d.return)&&i.call(d)}finally{if(o)throw o.error}}return l};t.forEach=function(e,t){for(var n=0;n<e.length;n++)t(e[n],n,e)};t.removeEventListener=function(e,t,n){e.removeEventListener(t,n)};t.addEventListener=function(e,n,r){return e.addEventListener(n,r),function(){t.removeEventListener(e,n,r)}};t.addClass=function(e,t){var n;Array.isArray(t)||(t=[t]),(n=e.classList).add.apply(n,i(t))};t.removeClass=function(e,t){e.classList.remove(t)};t.removeAllClass=function(e){e.className=""};t.hasClass=function(e,t){return e.classList.contains(t)}},function(e,t,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var o=r(n(3)),i=n(1),a=n(6),l=r(n(7)),u=n(12),s=n(0),d=function(){function e(e,t,n,r,o){void 0===o&&(o=!1),3===e.$node.nodeType&&3===t.$node.nodeType||s.eventEmitter.emit(s.INTERNAL_ERROR_EVENT,{type:i.ERROR.RANGE_NODE_INVALID}),this.start=u.formatDomNode(e),this.end=u.formatDomNode(t),this.text=n,this.frozen=o,this.id=r}return e.fromSelection=function(t){var n=a.getDomRange();if(!n)return null;var r={$node:n.startContainer,offset:n.startOffset},o={$node:n.endContainer,offset:n.endOffset},i=window.getSelection(),u=(null==i?void 0:i.toString())||n.toString(),s=t.call(r,o,u);return new e(r,o,u,s=null!=s?s:l.default())},e.prototype.serialize=function(e,t){var n,r=u.getDomMeta(this.start.$node,this.start.offset,e),i=u.getDomMeta(this.end.$node,this.end.offset,e);return t.Serialize.RecordInfo.isEmpty()||(n=t.Serialize.RecordInfo.call(this.start,this.end,e)),this.frozen=!0,new o.default(r,i,this.text,this.id,n)},e.removeDomRange=a.removeSelection,e}();t.default=d},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getTextFromRange=t.removeSelection=t.getDomRange=void 0;t.getDomRange=function(){var e=window.getSelection();return e.isCollapsed?(console.debug("no text selected"),null):e.getRangeAt(0)};t.removeSelection=function(){window.getSelection().removeAllRanges()};t.getTextFromRange=function(e){try{var t=e.cloneContents(),n=document.createElement("div");n.style.cssText="position:absolute;left:-9999px;top:-9999px;",document.body.appendChild(n),n.appendChild(t);var r=n.innerText;if(n.remove(),r)return r}catch(e){}return e.toString()}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function e(t){return t?(t^16*Math.random()>>t/4).toString(16):([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,e)}},function(e,t,n){e.exports=n(9)},function(e,t,n){"use strict";var r,o=this&&this.__extends||(r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__assign||function(){return(i=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var l=a(n(2)),u=a(n(5)),s=n(6),d=a(n(3)),c=a(n(7)),f=a(n(13)),h=a(n(14)),p=a(n(16)),E=a(n(17)),_=n(0),v=n(1),T=n(4),y=function(e){function t(t){var n=e.call(this)||this;n.event=h.default(),n.run=function(){return T.addEventListener(n.options.$root,n.event.PointerEnd,n._handleSelection)},n.stop=function(){T.removeEventListener(n.options.$root,n.event.PointerEnd,n._handleSelection)},n.addClass=function(e,t){n.getDoms(t).forEach((function(t){T.addClass(t,e)}))},n.removeClass=function(e,t){n.getDoms(t).forEach((function(t){T.removeClass(t,e)}))},n.getIdByDom=function(e){return T.getHighlightId(e,n.options.$root)},n.getExtraIdByDom=function(e){return T.getExtraHighlightId(e,n.options.$root)},n.getDoms=function(e){return e?T.getHighlightById(n.options.$root,e,n.options.wrapTag):T.getHighlightsByRoot(n.options.$root,n.options.wrapTag)},n.dispose=function(){var e=n.options.$root;T.removeEventListener(e,n.event.PointerOver,n._handleHighlightHover),T.removeEventListener(e,n.event.PointerEnd,n._handleSelection),T.removeEventListener(e,n.event.PointerTap,n._handleHighlightClick),n.removeAll()},n.setOption=function(e){n.options=i(i({},n.options),e),n.painter=new E.default({$root:n.options.$root,wrapTag:n.options.wrapTag,className:n.options.style.className,exceptSelectors:n.options.exceptSelectors},n.hooks)},n.fromRange=function(e){var t={$node:e.startContainer,offset:e.startOffset},r={$node:e.endContainer,offset:e.endOffset},o=s.getTextFromRange(e),i=n.hooks.Render.UUID.call(t,r,o);i=null!=i?i:c.default();var a=new u.default(t,r,o,i);return a?n._highlightFromHRange(a):(_.eventEmitter.emit(_.INTERNAL_ERROR_EVENT,{type:v.ERROR.RANGE_INVALID}),null)},n.fromStore=function(e,t,r,o,i){var a=new d.default(e,t,r,o,i);try{return n._highlightFromHSource(a),a}catch(e){return _.eventEmitter.emit(_.INTERNAL_ERROR_EVENT,{type:v.ERROR.HIGHLIGHT_SOURCE_RECREATE,error:e,detail:a}),null}},n._getHooks=function(){return{Render:{UUID:new f.default("Render.UUID"),SelectedNodes:new f.default("Render.SelectedNodes"),WrapNode:new f.default("Render.WrapNode")},Serialize:{Restore:new f.default("Serialize.Restore"),RecordInfo:new f.default("Serialize.RecordInfo")},Remove:{UpdateNodes:new f.default("Remove.UpdateNodes")}}},n._highlightFromHRange=function(e){var t=e.serialize(n.options.$root,n.hooks);return 0===n.painter.highlightRange(e).length?(_.eventEmitter.emit(_.INTERNAL_ERROR_EVENT,{type:v.ERROR.DOM_SELECTION_EMPTY}),null):(n.cache.save(t),n.emit(v.EventType.CREATE,{sources:[t],type:v.CreateFrom.INPUT},n),t)},n._handleSelection=function(){var e=u.default.fromSelection(n.hooks.Render.UUID);e&&(n._highlightFromHRange(e),u.default.removeDomRange())},n._handleHighlightHover=function(e){var t=e.target;if(!T.isHighlightWrapNode(t))return n._hoverId&&n.emit(v.EventType.HOVER_OUT,{id:n._hoverId},n,e),void(n._hoverId=null);var r=T.getHighlightId(t,n.options.$root);n._hoverId!==r&&(n._hoverId&&n.emit(v.EventType.HOVER_OUT,{id:n._hoverId},n,e),n._hoverId=r,n.emit(v.EventType.HOVER,{id:n._hoverId},n,e))},n._handleError=function(e){n.options.verbose&&console.warn(e)},n._handleHighlightClick=function(e){var t=e.target;if(T.isHighlightWrapNode(t)){var r=T.getHighlightId(t,n.options.$root);n.emit(v.EventType.CLICK,{id:r},n,e)}},n.options=_.getDefaultOptions(),n.hooks=n._getHooks(),n.setOption(t),n.cache=new p.default;var r=n.options.$root;return T.addEventListener(r,n.event.PointerOver,n._handleHighlightHover),T.addEventListener(r,n.event.PointerTap,n._handleHighlightClick),_.eventEmitter.on(_.INTERNAL_ERROR_EVENT,n._handleError),n}return o(t,e),t.prototype.remove=function(e){if(e){var t=this.painter.removeHighlight(e);this.cache.remove(e),t&&this.emit(v.EventType.REMOVE,{ids:[e]},this)}},t.prototype.removeAll=function(){this.painter.removeAllHighlight();var e=this.cache.removeAll();this.emit(v.EventType.REMOVE,{ids:e},this)},t.prototype._highlightFromHSource=function(e){void 0===e&&(e=[]);var t=this.painter.highlightSource(e);this.emit(v.EventType.CREATE,{sources:t,type:v.CreateFrom.STORE},this),this.cache.save(e)},t.event=v.EventType,t.isHighlightWrapNode=T.isHighlightWrapNode,t.isHighlightSource=function(e){return!!e.__isHighlightSource},t}(l.default);t.default=y},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.queryElementNode=t.getTextChildByOffset=void 0;var r=n(0);t.getTextChildByOffset=function(e,t){for(var n=[e],r=null,o=0,i=0;r=n.pop();){for(var a=r.childNodes,l=a.length-1;l>=0;l--)n.push(a[l]);if(3===r.nodeType&&(i=t-o,(o+=r.textContent.length)>=t))break}return r||(r=e),{$node:r,offset:i}};t.queryElementNode=function(e,t){return{start:e.startMeta.parentIndex===r.ROOT_IDX?t:t.getElementsByTagName(e.startMeta.parentTagName)[e.startMeta.parentIndex],end:e.endMeta.parentIndex===r.ROOT_IDX?t:t.getElementsByTagName(e.endMeta.parentTagName)[e.endMeta.parentIndex]}}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){return e.split("-").reduce((function(e,t,n){return e+(0===n?t:t[0].toUpperCase()+t.slice(1))}),"")}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.formatDomNode=t.getDomMeta=void 0;var r=n(0);t.getDomMeta=function(e,t,n){var o=function(e){if(e instanceof HTMLElement&&(!e.dataset||!e.dataset[r.CAMEL_DATASET_IDENTIFIER]))return e;for(var t=e.parentNode;null==t?void 0:t.dataset[r.CAMEL_DATASET_IDENTIFIER];)t=t.parentNode;return t}(e),i=o===n?r.ROOT_IDX:function(e,t){for(var n=e.tagName,o=t.getElementsByTagName(n),i=0;i<o.length;i++)if(e===o[i])return i;return r.UNKNOWN_IDX}(o,n),a=function(e,t){for(var n=[e],r=null,o=0;r=n.pop();){for(var i=r.childNodes,a=i.length-1;a>=0;a--)n.push(i[a]);if(3===r.nodeType&&r!==t)o+=r.textContent.length;else if(3===r.nodeType)break}return o}(o,e);return{parentTagName:o.tagName,parentIndex:i,textOffset:a+t}};t.formatDomNode=function(e){return 3===e.$node.nodeType||4===e.$node.nodeType||8===e.$node.nodeType?e:{$node:e.$node.childNodes[e.offset],offset:0}}},function(e,t,n){"use strict";var r=this&&this.__read||function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a},o=this&&this.__spread||function(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(r(arguments[t]));return e};Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e){this.name="",this.ops=[],this.name=e}return e.prototype.tap=function(e){var t=this;return-1===this.ops.indexOf(e)&&this.ops.push(e),function(){t.remove(e)}},e.prototype.remove=function(e){var t=this.ops.indexOf(e);t<0||this.ops.splice(t,1)},e.prototype.isEmpty=function(){return 0===this.ops.length},e.prototype.call=function(){for(var e,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return this.ops.forEach((function(n){e=n.apply(void 0,o(t))})),e},e}();t.default=i},function(e,t,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var o=n(1),i=r(n(15));t.default=function(){var e=i.default(window.navigator.userAgent);return{PointerEnd:e?o.UserInputEvent.touchend:o.UserInputEvent.mouseup,PointerTap:e?o.UserInputEvent.touchstart:o.UserInputEvent.click,PointerOver:e?o.UserInputEvent.touchstart:o.UserInputEvent.mouseover}}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=/Android|iPhone|BlackBerry|BB10|Opera Mini|Phone|Mobile|Silk|Windows Phone|Mobile(?:.+)Firefox\b/i;t.default=function(e){return r.test(e)}},function(e,t,n){"use strict";var r,o=this&&this.__extends||(r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var l=a(n(2)),u=n(1),s=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t._data=new Map,t}return o(t,e),Object.defineProperty(t.prototype,"data",{get:function(){return this.getAll()},set:function(e){throw u.ERROR.CACHE_SET_ERROR},enumerable:!1,configurable:!0}),t.prototype.save=function(e){var t=this;Array.isArray(e)?e.forEach((function(e){return t._data.set(e.id,e)})):this._data.set(e.id,e)},t.prototype.get=function(e){return this._data.get(e)},t.prototype.remove=function(e){this._data.delete(e)},t.prototype.getAll=function(){var e,t,n=[];try{for(var r=i(this._data),o=r.next();!o.done;o=r.next()){var a=o.value;n.push(a[1])}}catch(t){e={error:t}}finally{try{o&&!o.done&&(t=r.return)&&t.call(r)}finally{if(e)throw e.error}}return n},t.prototype.removeAll=function(){var e,t,n=[];try{for(var r=i(this._data),o=r.next();!o.done;o=r.next()){var a=o.value;n.push(a[0])}}catch(t){e={error:t}}finally{try{o&&!o.done&&(t=r.return)&&t.call(r)}finally{if(e)throw e.error}}return this._data=new Map,n},t}(l.default);t.default=s},function(e,t,n){"use strict";var r=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")},o=this&&this.__read||function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a},i=this&&this.__spread||function(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(o(arguments[t]));return e},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var l=a(n(3)),u=n(18),s=n(4),d=n(1),c=n(20),f=n(0),h=function(){function e(e,t){this.options={$root:e.$root,wrapTag:e.wrapTag,exceptSelectors:e.exceptSelectors,className:e.className},this.hooks=t,c.initDefaultStylesheet()}return e.prototype.highlightRange=function(e){var t=this;if(!e.frozen)throw d.ERROR.HIGHLIGHT_RANGE_FROZEN;var n=this.options,r=n.$root,o=n.className,i=n.exceptSelectors,a=this.hooks,l=u.getSelectedNodes(r,e.start,e.end,i);return a.Render.SelectedNodes.isEmpty()||(l=a.Render.SelectedNodes.call(e.id,l)||[]),l.map((function(n){var r=u.wrapHighlight(n,e,o,t.options.wrapTag);return a.Render.WrapNode.isEmpty()||(r=a.Render.WrapNode.call(e.id,r)),r}))},e.prototype.highlightSource=function(e){var t=this,n=Array.isArray(e)?e:[e],r=[];return n.forEach((function(e){if(e instanceof l.default){var n=e.deSerialize(t.options.$root,t.hooks);t.highlightRange(n).length>0?r.push(e):f.eventEmitter.emit(f.INTERNAL_ERROR_EVENT,{type:d.ERROR.HIGHLIGHT_SOURCE_NONE_RENDER,detail:e})}else f.eventEmitter.emit(f.INTERNAL_ERROR_EVENT,{type:d.ERROR.SOURCE_TYPE_ERROR})})),r},e.prototype.removeHighlight=function(e){var t,n,o=new RegExp("("+e+"\\"+f.ID_DIVISION+"|\\"+f.ID_DIVISION+"?"+e+"$)"),a=this.hooks,l=this.options.wrapTag,d=document.querySelectorAll(l+"[data-"+f.DATASET_IDENTIFIER+"]"),c=[],h=[],p=[];try{for(var E=r(d),_=E.next();!_.done;_=E.next()){var v=_.value,T=v.dataset[f.CAMEL_DATASET_IDENTIFIER],y=v.dataset[f.CAMEL_DATASET_IDENTIFIER_EXTRA];T!==e||y?T===e?h.push(v):T!==e&&o.test(y)&&p.push(v):c.push(v)}}catch(e){t={error:e}}finally{try{_&&!_.done&&(n=E.return)&&n.call(E)}finally{if(t)throw t.error}}return c.forEach((function(t){var n=t.parentNode,r=document.createDocumentFragment();s.forEach(t.childNodes,(function(e){return r.appendChild(e.cloneNode(!1))}));var o=t.previousSibling,i=t.nextSibling;n.replaceChild(r,t),u.normalizeSiblingText(o,!0),u.normalizeSiblingText(i,!1),a.Remove.UpdateNodes.call(e,t,"remove")})),h.forEach((function(t){var n=t.dataset,r=n[f.CAMEL_DATASET_IDENTIFIER_EXTRA].split(f.ID_DIVISION),o=r.shift(),u=document.querySelector(l+"[data-"+f.DATASET_IDENTIFIER+'="'+o+'"]');u&&(s.removeAllClass(t),s.addClass(t,i(u.classList))),n[f.CAMEL_DATASET_IDENTIFIER]=o,n[f.CAMEL_DATASET_IDENTIFIER_EXTRA]=r.join(f.ID_DIVISION),a.Remove.UpdateNodes.call(e,t,"id-update")})),p.forEach((function(t){var n=t.dataset[f.CAMEL_DATASET_IDENTIFIER_EXTRA];t.dataset[f.CAMEL_DATASET_IDENTIFIER_EXTRA]=n.replace(o,""),a.Remove.UpdateNodes.call(e,t,"extra-update")})),c.length+h.length+p.length!==0},e.prototype.removeAllHighlight=function(){var e=this.options,t=e.wrapTag,n=e.$root;s.getHighlightsByRoot(n,t).forEach((function(e){var t=e.parentNode,n=document.createDocumentFragment();s.forEach(e.childNodes,(function(e){return n.appendChild(e.cloneNode(!1))})),t.replaceChild(n,e)}))},e}();t.default=h},function(e,t,n){"use strict";var r=this&&this.__read||function(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a},o=this&&this.__spread||function(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(r(arguments[t]));return e};Object.defineProperty(t,"__esModule",{value:!0}),t.normalizeSiblingText=t.wrapHighlight=t.getSelectedNodes=void 0;var i=n(1),a=n(4),l=n(0),u=n(19),s=function(e,t){if(!e)return!1;if(/^\./.test(t)){var n=t.replace(/^\./,"");return e&&a.hasClass(e,n)}if(/^#/.test(t)){var r=t.replace(/^#/,"");return e&&e.id===r}var o=t.toUpperCase();return e&&e.tagName===o};t.getSelectedNodes=function(e,t,n,r){var o=t.$node,a=n.$node,l=t.offset,u=n.offset;if(o===a&&o instanceof Text)return function(e,t,n,r){for(var o=e,a=function(e){return null==r?void 0:r.some((function(t){return s(e,t)}))};o;){if(1===o.nodeType&&a(o))return[];o=o.parentNode}e.splitText(t);var l=e.nextSibling;return l.splitText(n-t),[{$node:l,type:i.SelectedNodeType.text,splitType:i.SplitType.both}]}(o,l,u,r);for(var d=[e],c=[],f=function(e){return null==r?void 0:r.some((function(t){return s(e,t)}))},h=!1,p=null;p=d.pop();)if(1!==p.nodeType||!f(p)){for(var E=p.childNodes,_=E.length-1;_>=0;_--)d.push(E[_]);if(p===o){if(3===p.nodeType){p.splitText(l);var v=p.nextSibling;c.push({$node:v,type:i.SelectedNodeType.text,splitType:i.SplitType.head})}h=!0}else{if(p===a){if(3===p.nodeType)(v=p).splitText(u),c.push({$node:v,type:i.SelectedNodeType.text,splitType:i.SplitType.tail});break}h&&3===p.nodeType&&c.push({$node:p,type:i.SelectedNodeType.text,splitType:i.SplitType.none})}}return c};var d=function(e,t){var n=Array.isArray(t)?t:[t];return(n=0===n.length?[l.getDefaultOptions().style.className]:n).forEach((function(t){a.addClass(e,t)})),e},c=function(e){return!e||!e.textContent};t.wrapHighlight=function(e,t,n,r){var s=e.$node.parentNode,f=e.$node.previousSibling,h=e.$node.nextSibling;return a.isHighlightWrapNode(s)?!a.isHighlightWrapNode(s)||c(f)&&c(h)?function(e,t,n){var r=e.$node.parentNode,o=r;a.removeAllClass(o),d(o,n);var i=r.dataset,u=i[l.CAMEL_DATASET_IDENTIFIER];return i[l.CAMEL_DATASET_IDENTIFIER]=t.id,i[l.CAMEL_DATASET_IDENTIFIER_EXTRA]=i[l.CAMEL_DATASET_IDENTIFIER_EXTRA]?u+l.ID_DIVISION+i[l.CAMEL_DATASET_IDENTIFIER_EXTRA]:u,o}(e,t,n):function(e,t,n,r){var a=document.createElement(r),s=e.$node.parentNode,c=e.$node.previousSibling,f=e.$node.nextSibling,h=document.createDocumentFragment(),p=s.dataset[l.CAMEL_DATASET_IDENTIFIER],E=s.dataset[l.CAMEL_DATASET_IDENTIFIER_EXTRA],_=E?p+l.ID_DIVISION+E:p;a.setAttribute("data-"+l.DATASET_IDENTIFIER,t.id),a.setAttribute("data-"+l.DATASET_IDENTIFIER_EXTRA,_),a.appendChild(e.$node.cloneNode(!1));var v,T=!1,y=!1;c&&((g=s.cloneNode(!1)).textContent=c.textContent,h.appendChild(g),T=!0);var g,I=[];(Array.isArray(n)?I.push.apply(I,o(n)):I.push(n),d(a,u.unique(I)),h.appendChild(a),f)&&((g=s.cloneNode(!1)).textContent=f.textContent,h.appendChild(g),y=!0);return v=T&&y?i.SplitType.both:T?i.SplitType.head:y?i.SplitType.tail:i.SplitType.none,a.setAttribute("data-"+l.DATASET_SPLIT_TYPE,v),s.parentNode.replaceChild(h,s),a}(e,t,n,r):function(e,t,n,r){var o=document.createElement(r);return d(o,n),o.appendChild(e.$node.cloneNode(!1)),e.$node.parentNode.replaceChild(o,e.$node),o.setAttribute("data-"+l.DATASET_IDENTIFIER,t.id),o.setAttribute("data-"+l.DATASET_SPLIT_TYPE,e.splitType),o.setAttribute("data-"+l.DATASET_IDENTIFIER_EXTRA,""),o}(e,t,n,r)};t.normalizeSiblingText=function(e,t){if(void 0===t&&(t=!0),e&&3===e.nodeType){var n=t?e.nextSibling:e.previousSibling;if(3===n.nodeType){var r=n.nodeValue;e.nodeValue=t?e.nodeValue+r:r+e.nodeValue,n.parentNode.removeChild(n)}}}},function(e,t,n){"use strict";var r=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(t,"__esModule",{value:!0}),t.unique=void 0;t.unique=function(e){var t,n,o=[];try{for(var i=r(e),a=i.next();!a.done;a=i.next()){var l=a.value;-1===o.indexOf(l)&&o.push(l)}}catch(e){t={error:e}}finally{try{a&&!a.done&&(n=i.return)&&n.call(i)}finally{if(t)throw t.error}}return o}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.initDefaultStylesheet=void 0;var r=n(0);t.initDefaultStylesheet=function(){var e=r.STYLESHEET_ID,t=document.getElementById(e);if(!t){var n=document.createTextNode(r.getStylesheet());(t=document.createElement("style")).id=e,t.appendChild(n),document.head.appendChild(t)}return t}}]).default}));
|
|
3
|
+
//# sourceMappingURL=web-highlighter.min.js.map
|