@ohos-ports/advanced-mark.js 3.0.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.
@@ -0,0 +1,210 @@
1
+
2
+ // Type definitions for advanced-mark.js v1.1.0
3
+ // Based on "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/mark.js"
4
+
5
+ declare namespace Mark {
6
+
7
+ interface BoundaryObject {
8
+ tags?: string[];
9
+ extend?: boolean;
10
+ char?: string;
11
+ }
12
+
13
+ interface ShadowObject {
14
+ style: string;
15
+ }
16
+
17
+ interface IframesObject {
18
+ style: string;
19
+ }
20
+
21
+ interface AccuracyObject {
22
+ value: 'exactly' | 'startsWith' | 'complementary';
23
+ limiters: string | string[];
24
+ }
25
+
26
+ interface MarkOptions {
27
+ element?: string;
28
+ window?: Window;
29
+ className?: string;
30
+ exclude?: string | string[];
31
+ separateWordSearch?: boolean | 'preserveTerms';
32
+ acrossElements?: boolean;
33
+ accuracy?: 'partially' | 'exactly' | 'startsWith' | 'complementary' | AccuracyObject;
34
+ diacritics?: boolean;
35
+ synonyms?: { [index: string] : string | string[] };
36
+ caseSensitive?: boolean;
37
+ ignoreJoiners?: boolean;
38
+ ignorePunctuation?: string | string[];
39
+ wildcards?: 'disabled' | 'enabled' | 'withSpaces';
40
+ iframes?: boolean | IframesObject;
41
+ iframesTimeout?: number;
42
+
43
+ highlight?: Highlight;
44
+ highlightName?: string;
45
+ staticRanges?: boolean;
46
+ rangeAcrossElements?: boolean;
47
+ combineby?: number;
48
+ blockElementsBoundary?: boolean | BoundaryObject;
49
+ shadowDOM?: boolean | ShadowObject;
50
+
51
+ filter?(
52
+ nodeOrArray: Text | Text[], term: string, totalMatchesSoFar: number, termMatchesSoFar: number, filterInfo: MarkFilterInfo
53
+ ) : boolean;
54
+ each?(elementOrRange: Element | StaticRange | Range, eachInfo: MarkEachInfo) : void;
55
+ done?(totalMarks: number, totalMatches: number, termStats: TermStats) : void;
56
+
57
+ noMatch?(term: string[]) : void;
58
+ debug?: boolean;
59
+ log?: object;
60
+ }
61
+
62
+ interface MarkFilterInfo {
63
+ match: RegExpExecArray;
64
+ matchStart?: boolean;
65
+ count: number;
66
+ abort: boolean;
67
+ }
68
+
69
+ interface MarkEachInfo {
70
+ match: RegExpExecArray;
71
+ matchStart?: boolean;
72
+ count: number;
73
+ abort: boolean;
74
+ }
75
+
76
+ interface TermStats {
77
+ [index: string] : number;
78
+ }
79
+
80
+ interface RegExpOptions {
81
+ element?: string;
82
+ className?: string;
83
+ exclude?: string | string[];
84
+ acrossElements?: boolean;
85
+ ignoreGroups?: number;
86
+ iframes?: boolean | IframesObject;
87
+ iframesTimeout?: number;
88
+
89
+ highlight?: Highlight;
90
+ highlightName?: string;
91
+ staticRanges?: boolean;
92
+ rangeAcrossElements?: boolean;
93
+ separateGroups?: boolean;
94
+ wrapAllRanges?: boolean;
95
+ blockElementsBoundary?: boolean | BoundaryObject;
96
+ shadowDOM?: boolean | ShadowObject;
97
+
98
+ filter?(nodeOrArray: Text | Text[], regexp: string, matchesSoFar: number, filterInfo: RegExpFilterInfo) : boolean;
99
+ each?(elementOrRange: Element | StaticRange | Range, eachInfo: RegExpEachInfo) : void;
100
+ done?(totalMarks: number, totalMatches: number) : void;
101
+
102
+ noMatch?(regexp: string) : void;
103
+ debug?: boolean;
104
+ log?: object;
105
+ }
106
+
107
+ interface RegExpFilterInfo {
108
+ match: RegExpExecArray;
109
+ matchStart?: boolean;
110
+ count: number;
111
+ groupIndex?: number;
112
+ abort: boolean;
113
+ }
114
+
115
+ interface RegExpEachInfo {
116
+ match: RegExpExecArray;
117
+ matchStart?: boolean;
118
+ count: number;
119
+ groupIndex?: number;
120
+ groupStart?: boolean;
121
+ abort: boolean;
122
+ }
123
+
124
+ interface RangesOptions {
125
+ element?: string;
126
+ className?: string;
127
+ exclude?: string | string[];
128
+ iframes?: boolean | IframesObject;
129
+ iframesTimeout?: number;
130
+
131
+ highlight?: Highlight;
132
+ highlightName?: string;
133
+ staticRanges?: boolean;
134
+ rangeAcrossElements?: boolean;
135
+ wrapAllRanges?: boolean;
136
+ markLines?: boolean;
137
+ shadowDOM?: boolean | ShadowObject;
138
+
139
+ filter?(nodeOrArray: Text | Text[], range: MarkRange, matchingString: string, currentIndex: number) : boolean;
140
+ each?(elementOrRange: Element | StaticRange | Range, range: MarkRange, eachInfo: RangeEachInfo) : void;
141
+ done?(totalMarks: number, totalRanges: number) : void;
142
+
143
+ noMatch?(range: MarkRange) : void;
144
+ debug?: boolean;
145
+ log?: object;
146
+ }
147
+
148
+ interface MarkRange {
149
+ start: number;
150
+ length: number;
151
+ }
152
+
153
+ interface RangeEachInfo {
154
+ matchStart?: boolean;
155
+ count: number;
156
+ }
157
+
158
+ interface UnmarkOptions {
159
+ element?: string;
160
+ className?: string;
161
+ exclude?: string | string[];
162
+ iframes?: boolean | IframesObject;
163
+ iframesTimeout?: number;
164
+ shadowDOM?: boolean;
165
+ highlight?: Highlight;
166
+ highlightName?: string | string[];
167
+
168
+ done?() : void;
169
+ debug?: boolean;
170
+ log?: object;
171
+ }
172
+ }
173
+
174
+ declare class Mark {
175
+ constructor(context: string | HTMLElement | ReadonlyArray<HTMLElement> | NodeList | null);
176
+
177
+ /**
178
+ * Highlights the specified search terms.
179
+ * @param term The string to be marked. Can also be an array with multiple strings.
180
+ * Note that keywords will be escaped. If you need to mark unescaped keywords (e.g. containing a pattern),
181
+ * have a look at the `markRegExp()`
182
+ * @param options Optional options
183
+ */
184
+ mark(term: string | ReadonlyArray<string>, options?: Mark.MarkOptions) : void;
185
+
186
+ /**
187
+ * Highlights a custom regular expression.
188
+ * @param regexp The regular expression to be marked. Example: /Lor[^]?m/gmi.
189
+ * Note that the `g` flag must be present when `acrossElements : true`, otherwise the RegExp is recompiled.
190
+ * @param options Optional options
191
+ */
192
+ markRegExp(regexp: RegExp, options?: Mark.RegExpOptions) : void;
193
+
194
+ /**
195
+ * A method to mark ranges with a start position and length. They will be applied
196
+ * to text nodes in the specified context.
197
+ * @param ranges An array of objects with a start and length property.
198
+ * Note that the start positions must be specified including whitespace characters.
199
+ * @param options Optional options
200
+ */
201
+ markRanges(ranges: ReadonlyArray<Mark.MarkRange>, options?: Mark.RangesOptions) : void;
202
+
203
+ /**
204
+ * A method to remove mark elements created by mark.js and normalize text nodes.
205
+ * @param options Optional options
206
+ */
207
+ unmark(options?: Mark.UnmarkOptions) : void;
208
+ }
209
+
210
+ export = Mark;
package/src/vanilla.js ADDED
@@ -0,0 +1,25 @@
1
+ import MarkJS from './lib/mark';
2
+
3
+ export default function Mark(ctx) {
4
+ const instance = new MarkJS(ctx);
5
+ this.mark = (sv, opt) => {
6
+ instance.mark(sv, opt);
7
+ return this;
8
+ };
9
+ this.markRegExp = (sv, opt) => {
10
+ instance.markRegExp(sv, opt);
11
+ return this;
12
+ };
13
+ this.markRanges = (sv, opt) => {
14
+ instance.markRanges(sv, opt);
15
+ return this;
16
+ };
17
+ this.unmark = (opt) => {
18
+ instance.unmark(opt);
19
+ return this;
20
+ };
21
+ this.getVersion = () => {
22
+ return '[VI]{version}[/VI]';
23
+ };
24
+ return this;
25
+ }