@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.
Files changed (88) hide show
  1. package/.cursor/environment.json +6 -0
  2. package/.eslintrc.js +250 -0
  3. package/.prettierrc +9 -0
  4. package/.travis.yml +17 -0
  5. package/CHANGELOG.md +220 -0
  6. package/LICENSE +21 -0
  7. package/README.md +371 -0
  8. package/README.zh_CN.md +367 -0
  9. package/config/base.config.js +25 -0
  10. package/config/base.example.config.js +38 -0
  11. package/config/paths.js +22 -0
  12. package/config/server.config.js +17 -0
  13. package/config/webpack.config.dev.js +18 -0
  14. package/config/webpack.config.example.js +20 -0
  15. package/config/webpack.config.prod.js +28 -0
  16. package/dist/data/cache.d.ts +13 -0
  17. package/dist/index.d.ts +58 -0
  18. package/dist/model/range/dom.d.ts +6 -0
  19. package/dist/model/range/index.d.ts +20 -0
  20. package/dist/model/range/selection.d.ts +14 -0
  21. package/dist/model/source/dom.d.ts +23 -0
  22. package/dist/model/source/index.d.ts +18 -0
  23. package/dist/painter/dom.d.ts +22 -0
  24. package/dist/painter/index.d.ts +19 -0
  25. package/dist/painter/style.d.ts +1 -0
  26. package/dist/types/index.d.ts +102 -0
  27. package/dist/util/camel.d.ts +5 -0
  28. package/dist/util/const.d.ts +41 -0
  29. package/dist/util/deferred.d.ts +9 -0
  30. package/dist/util/dom.d.ts +32 -0
  31. package/dist/util/event.emitter.d.ts +13 -0
  32. package/dist/util/hook.d.ts +15 -0
  33. package/dist/util/interaction.d.ts +6 -0
  34. package/dist/util/is.mobile.d.ts +5 -0
  35. package/dist/util/tool.d.ts +4 -0
  36. package/dist/util/uuid.d.ts +4 -0
  37. package/dist/web-highlighter.min.js +3 -0
  38. package/dist/web-highlighter.min.js.map +1 -0
  39. package/docs/ADVANCE.md +113 -0
  40. package/docs/ADVANCE.zh_CN.md +111 -0
  41. package/docs/img/create-flow.jpg +0 -0
  42. package/docs/img/create-flow.zh_CN.jpg +0 -0
  43. package/docs/img/logo.png +0 -0
  44. package/docs/img/remove-flow.jpg +0 -0
  45. package/docs/img/remove-flow.zh_CN.jpg +0 -0
  46. package/docs/img/sample.gif +0 -0
  47. package/example/index.css +2 -0
  48. package/example/index.js +214 -0
  49. package/example/local.store.js +72 -0
  50. package/example/my.css +119 -0
  51. package/example/tpl.html +59 -0
  52. package/package.json +103 -0
  53. package/script/build.js +17 -0
  54. package/script/convet-md.js +25 -0
  55. package/script/dev.js +22 -0
  56. package/src/data/cache.ts +57 -0
  57. package/src/index.ts +285 -0
  58. package/src/model/range/dom.ts +94 -0
  59. package/src/model/range/index.ts +88 -0
  60. package/src/model/range/selection.ts +55 -0
  61. package/src/model/source/dom.ts +66 -0
  62. package/src/model/source/index.ts +54 -0
  63. package/src/painter/dom.ts +345 -0
  64. package/src/painter/index.ts +199 -0
  65. package/src/painter/style.ts +21 -0
  66. package/src/types/index.ts +118 -0
  67. package/src/util/camel.ts +6 -0
  68. package/src/util/const.ts +54 -0
  69. package/src/util/deferred.ts +37 -0
  70. package/src/util/dom.ts +155 -0
  71. package/src/util/event.emitter.ts +45 -0
  72. package/src/util/hook.ts +52 -0
  73. package/src/util/interaction.ts +20 -0
  74. package/src/util/is.mobile.ts +7 -0
  75. package/src/util/tool.ts +14 -0
  76. package/src/util/uuid.ts +10 -0
  77. package/test/api.spec.ts +555 -0
  78. package/test/event.spec.ts +284 -0
  79. package/test/fixtures/broken.json +32 -0
  80. package/test/fixtures/index.html +11 -0
  81. package/test/fixtures/source.json +47 -0
  82. package/test/hook.spec.ts +244 -0
  83. package/test/integrate.spec.ts +48 -0
  84. package/test/mobile.spec.ts +87 -0
  85. package/test/option.spec.ts +212 -0
  86. package/test/util.spec.ts +244 -0
  87. package/test-newlines.html +226 -0
  88. package/tsconfig.json +23 -0
@@ -0,0 +1,6 @@
1
+ {
2
+ "snapshot": "snapshot-20250519-c7915489-4453-40ca-9eea-6e52326ce452",
3
+ "install": "",
4
+ "start": "",
5
+ "terminals": []
6
+ }
package/.eslintrc.js ADDED
@@ -0,0 +1,250 @@
1
+ module.exports = {
2
+ parser: '@typescript-eslint/parser',
3
+ parserOptions: {
4
+ project: 'tsconfig.json',
5
+ sourceType: 'module',
6
+ },
7
+ plugins: [
8
+ '@typescript-eslint/eslint-plugin',
9
+ 'prettier',
10
+ 'import',
11
+ ],
12
+ extends: [
13
+ "eslint:all",
14
+ 'plugin:@typescript-eslint/all',
15
+ 'prettier',
16
+ 'prettier/@typescript-eslint',
17
+ ],
18
+ root: true,
19
+ env: {
20
+ es6: true,
21
+ node: true,
22
+ jest: true,
23
+ },
24
+ rules: {
25
+ "array-bracket-newline": [
26
+ "error",
27
+ "consistent"
28
+ ],
29
+ "array-element-newline": [
30
+ "error",
31
+ "consistent"
32
+ ],
33
+ "arrow-parens": [
34
+ "error",
35
+ "as-needed"
36
+ ],
37
+ "class-methods-use-this": "off",
38
+ "capitalized-comments": "off",
39
+ "comma-dangle": [
40
+ "error",
41
+ "always-multiline"
42
+ ],
43
+ "dot-location": [
44
+ "error",
45
+ "property"
46
+ ],
47
+ "func-names": [
48
+ "error",
49
+ "as-needed"
50
+ ],
51
+ "id-length": "off",
52
+ "implicit-arrow-linebreak": "off",
53
+ "init-declarations": "off",
54
+ "max-len": [
55
+ "error",
56
+ 120
57
+ ],
58
+ "max-lines": "off",
59
+ "max-lines-per-function": "off",
60
+ "max-params": "off",
61
+ "max-statements": "off",
62
+ "multiline-comment-style": "off",
63
+ "multiline-ternary": [
64
+ "error",
65
+ "always-multiline"
66
+ ],
67
+ "newline-per-chained-call": [
68
+ "error",
69
+ {
70
+ "ignoreChainWithDepth": 2
71
+ }
72
+ ],
73
+ "no-await-in-loop": "off",
74
+ "no-bitwise": "off",
75
+ "no-confusing-arrow": "off",
76
+ "no-constant-condition": [
77
+ "error",
78
+ {
79
+ "checkLoops": false
80
+ }
81
+ ],
82
+ "no-continue": "off",
83
+ "no-duplicate-imports": "off",
84
+ "no-param-reassign": "off",
85
+ "no-underscore-dangle": "off",
86
+ "import/no-duplicates": [
87
+ "error",
88
+ {
89
+ "considerQueryString": true
90
+ }
91
+ ],
92
+ "no-empty": "off",
93
+ "no-implicit-coercion": "off",
94
+ "no-invalid-this": "off",
95
+ "no-mixed-operators": "off",
96
+ "no-multiple-empty-lines": [
97
+ "error",
98
+ {
99
+ "max": 2,
100
+ "maxEOF": 1
101
+ }
102
+ ],
103
+ "no-plusplus": [
104
+ "error",
105
+ {
106
+ "allowForLoopAfterthoughts": true
107
+ }
108
+ ],
109
+ "no-process-env": "off",
110
+ "no-shadow": "off",
111
+ "no-ternary": "off",
112
+ "no-unused-expressions": "off",
113
+ "no-warning-comments": "off",
114
+ "new-cap": "off",
115
+ "one-var": [
116
+ "error",
117
+ "never"
118
+ ],
119
+ "padded-blocks": [
120
+ "error",
121
+ "never"
122
+ ],
123
+ "padding-line-between-statements": [
124
+ "error",
125
+ {
126
+ "blankLine": "always",
127
+ "prev": [
128
+ "const",
129
+ "let",
130
+ "var"
131
+ ],
132
+ "next": "*"
133
+ },
134
+ {
135
+ "blankLine": "always",
136
+ "prev": "*",
137
+ "next": [
138
+ "const",
139
+ "let",
140
+ "var"
141
+ ]
142
+ },
143
+ {
144
+ "blankLine": "any",
145
+ "prev": [
146
+ "const",
147
+ "let",
148
+ "var"
149
+ ],
150
+ "next": [
151
+ "const",
152
+ "let",
153
+ "var"
154
+ ]
155
+ },
156
+ {
157
+ "blankLine": "always",
158
+ "prev": "*",
159
+ "next": "return"
160
+ },
161
+ {
162
+ "blankLine": "always",
163
+ "prev": "block-like",
164
+ "next": "*"
165
+ },
166
+ {
167
+ "blankLine": "always",
168
+ "prev": "*",
169
+ "next": "block-like"
170
+ }
171
+ ],
172
+ "prefer-destructuring": "off",
173
+ "quote-props": [
174
+ "error",
175
+ "as-needed"
176
+ ],
177
+ "quotes": [
178
+ "error",
179
+ "single",
180
+ {
181
+ "avoidEscape": true
182
+ }
183
+ ],
184
+ "object-curly-spacing": [
185
+ "error",
186
+ "always"
187
+ ],
188
+ "require-atomic-updates": "off",
189
+ "require-unicode-regexp": "off",
190
+ "semi": "off",
191
+ "sort-imports": "off",
192
+ "sort-keys": "off",
193
+ "wrap-regex": "off",
194
+ "import/default": "off",
195
+
196
+ "@typescript-eslint/explicit-function-return-type": "off",
197
+ "@typescript-eslint/explicit-member-accessibility": [
198
+ "error",
199
+ {
200
+ "accessibility": "no-public"
201
+ }
202
+ ],
203
+ "@typescript-eslint/explicit-module-boundary-types": "off",
204
+ "@typescript-eslint/generic-type-naming": "off",
205
+ "@typescript-eslint/init-declarations": "off",
206
+ "@typescript-eslint/naming-convention": "off",
207
+ "@typescript-eslint/no-dynamic-delete": "off",
208
+ "@typescript-eslint/no-empty-function": "off",
209
+ "@typescript-eslint/no-explicit-any": "off",
210
+ "@typescript-eslint/no-extraneous-class": [
211
+ "error",
212
+ {
213
+ "allowWithDecorator": true
214
+ }
215
+ ],
216
+ "@typescript-eslint/no-invalid-this": "off",
217
+ "@typescript-eslint/no-invalid-void-type": "off",
218
+ "@typescript-eslint/no-magic-numbers": "off",
219
+ "@typescript-eslint/no-misused-promises": "off",
220
+ "@typescript-eslint/no-parameter-properties": "off",
221
+ "@typescript-eslint/no-throw-literal": "off",
222
+ "@typescript-eslint/no-type-alias": "off",
223
+ "@typescript-eslint/no-unnecessary-condition": "off",
224
+ "@typescript-eslint/no-unsafe-assignment": "off",
225
+ "@typescript-eslint/no-unused-expressions": "off",
226
+ "@typescript-eslint/no-unused-vars": [
227
+ "error",
228
+ {
229
+ "argsIgnorePattern": "^_$",
230
+ "varsIgnorePattern": "^_$",
231
+ "ignoreRestSiblings": true
232
+ }
233
+ ],
234
+ "@typescript-eslint/prefer-includes": "off",
235
+ "@typescript-eslint/prefer-nullish-coalescing": "off",
236
+ "@typescript-eslint/prefer-readonly-parameter-types": "off",
237
+ "@typescript-eslint/prefer-string-starts-ends-with": "off",
238
+ "@typescript-eslint/promise-function-async": "off",
239
+ "@typescript-eslint/restrict-template-expressions": [
240
+ "warn",
241
+ {
242
+ "allowNumber": true
243
+ }
244
+ ],
245
+ "@typescript-eslint/semi": "error",
246
+ "@typescript-eslint/strict-boolean-expressions": "off",
247
+ "@typescript-eslint/typedef": "off",
248
+ "prettier/prettier": "error"
249
+ },
250
+ };
package/.prettierrc ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "singleQuote": true,
3
+ "trailingComma": "all",
4
+ "printWidth": 120,
5
+ "tabWidth": 4,
6
+ "arrowParens": "avoid",
7
+ "bracketSpacing": true,
8
+ "parser": "typescript"
9
+ }
package/.travis.yml ADDED
@@ -0,0 +1,17 @@
1
+ language: node_js
2
+
3
+ node_js:
4
+ - 10
5
+
6
+ branches:
7
+ only:
8
+ - master
9
+
10
+ install:
11
+ - npm install
12
+
13
+ script:
14
+ - npm run build
15
+ - npm run coverage
16
+
17
+ after_script: "cat coverage/lcov.info | node_modules/coveralls/bin/coveralls.js"
package/CHANGELOG.md ADDED
@@ -0,0 +1,220 @@
1
+ # CHANGELOG
2
+
3
+ ## v0.7.4
4
+
5
+ ### Fix
6
+
7
+ Removing unsupported APIs to fix compatibility issues in IE11:
8
+
9
+ - [Array.prototype.includes](https://caniuse.com/array-includes)
10
+ - [String: startsWith](https://caniuse.com/mdn-javascript_builtins_string_startswith)
11
+ - [RegExp: unicode](https://caniuse.com/mdn-javascript_builtins_regexp_unicode)
12
+
13
+ ---
14
+
15
+ ## v0.7.3
16
+
17
+ ### Fix
18
+
19
+ - highlight wrapper inside another wrapper not get updated when deleting [#80](https://github.com/alienzhou/web-highlighter/pull/80)
20
+ - make the className the latest one when wrapping a partial or an overlap node [#82](https://github.com/alienzhou/web-highlighter/pull/82)
21
+
22
+ ### Improvement
23
+
24
+ - better typings for event emitter [#81](https://github.com/alienzhou/web-highlighter/pull/81)
25
+ - tsconfig path alias and npm scripts [#84](https://github.com/alienzhou/web-highlighter/pull/84)
26
+
27
+ ---
28
+
29
+ ## v0.7.2
30
+
31
+ ### Fix
32
+
33
+ - including type declarations in the `package.json`
34
+ - making public `.options` a private field
35
+
36
+ ---
37
+
38
+ ## v0.7.1
39
+
40
+ ### Features
41
+
42
+ - Generating .d.ts files for projects using typescript.
43
+
44
+ ### Fix
45
+
46
+ - Select the range's container element correctly when it is not Text/Comment/CDATASection.
47
+
48
+ ---
49
+
50
+ ## v0.7.0
51
+
52
+ ### Features
53
+
54
+ - Make get id methods more flexible.
55
+ - It will get correct id(s) inside a wrapper. No need to be a wrapper element.
56
+ - It is limited in the root scope.
57
+
58
+ ### Fix
59
+
60
+ - Retain the wrapper's classname when wrapping a partial node.
61
+
62
+ ---
63
+
64
+ ## v0.6.0
65
+
66
+ ### Features
67
+
68
+ - Add `.getExtraIdByDom` instance method which helps get extra ids from a wrapper.
69
+ - Add a new hook: `Serialize.Restore`. You can use it to customize your own restoring method. When you tap this hook, the HighlightSource instance will use the function you pass to calculate the start and end nodes' info.
70
+ - Support remove function in hooks. Now `hook.tap()` will return a function for removing it. Besides, you can also call `hook.remove()` to remove a tapped function.
71
+
72
+ ### Fix
73
+
74
+ - When pre&next nodes are empty texts, the text node's wrapper should not be split.
75
+ - Avoid add duplicate functions to a hook.
76
+
77
+ ### Other updates
78
+
79
+ - Add unit tests for hook, event emitter and new features.
80
+ - Use unknown type instead of any.
81
+
82
+ ---
83
+
84
+ ## v0.5.2
85
+
86
+ ### Features
87
+
88
+ - Support verbose configuration. It decides whether warning&error message will be output.
89
+ - Add a static method .isHighlightWrapNode(). You can use it to test whether a node(DOM) is a highlight wrapper.
90
+
91
+ ### Fix
92
+
93
+ - Prevent emit REMOVE event when no node is affected by calling `.remove()` and `.removeAll()`
94
+ - Fix the bug in `.getAll`, now it will return correct data
95
+ - Prevent injecting duplicate stylesheets when one has been injected
96
+
97
+ ### Other updates
98
+
99
+ - Add a suit of unit tests to ensure the code quality.
100
+ - Refactor the way of error reporting.
101
+ - Remove `.dataset` polyfill.
102
+
103
+ ---
104
+
105
+ ## v0.5.1
106
+
107
+ ### Fix
108
+
109
+ - fix the bug: When the root node has no children (except text nodes), the highlights can't be recreate by sources.
110
+
111
+ ## v0.6.0-beta.0
112
+
113
+ ### Features
114
+
115
+ - add a new hook: Serialize.Restore
116
+
117
+ > Customize your own restoring method. When you tap this hook, the HighlightSource instance will use the function you pass to calculate the start and end nodes' info.
118
+
119
+ ---
120
+
121
+ ## v0.5.0
122
+
123
+ ### Features
124
+
125
+ - add an option: support changing the default wrapper's tag name
126
+
127
+ using it as below
128
+
129
+ ```typescript
130
+ const highlighter = new Highlighter({
131
+ wrapTag: 'b'
132
+ });
133
+ ```
134
+
135
+ ---
136
+
137
+ ## 0.4.0-beta.0
138
+
139
+ ### Features
140
+
141
+ - support highlighting on mobile devices:
142
+ - automatically detect whether mobile devices
143
+ - use touch events when on mobile devices
144
+
145
+ ### Other updates
146
+
147
+ - source code: provide some internal methods for dom operation
148
+ - example app: bugfix & update
149
+
150
+ ---
151
+
152
+ ## v0.3.5
153
+
154
+ ### Fix
155
+
156
+ - Bugfix: The highlighter.removeAll() method doesn't work
157
+
158
+ ---
159
+
160
+ ## v0.3.4
161
+
162
+ ### Fix
163
+
164
+ - bugfix: `highlighter.removeAll()` does not work properly
165
+
166
+ ---
167
+
168
+ ## v0.3.3
169
+
170
+ ### Fix
171
+
172
+ - hook: Remove.UpdateNode --> Remove.UpdateNodes
173
+
174
+ ### Other update
175
+
176
+ - docs: english version
177
+ - use new README for the example
178
+
179
+ ---
180
+
181
+ ## v0.3.2
182
+
183
+ ### Updates
184
+
185
+ - refactor: split some painter's functions
186
+ - update: update docs and the example
187
+
188
+ ---
189
+
190
+ ## v0.3.1
191
+
192
+ ### Updates
193
+
194
+ - Structure refactor
195
+ - Handling compatibility issues
196
+ - Remove unnecessary modules
197
+
198
+ ---
199
+
200
+ ## v0.0.3
201
+
202
+ ### Features
203
+
204
+ - support setting config dynamically
205
+
206
+ ### Break Changes
207
+
208
+ - rename `.render()` to `.fromSource()`
209
+ - rename `.highlight()` to `.fromRange()`
210
+ - remove `.init` method and `highlight:init` event
211
+
212
+ ---
213
+
214
+ ## v0.0.2
215
+
216
+ ### Features
217
+
218
+ - set highlight style (class) by id
219
+ - get highlight position info (offsetTop, offsetLeft)
220
+ - highlighting web text by passing range manually
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Alien ZHOU
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.