@zipify/wysiwyg 1.1.1 → 1.2.1-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.
Files changed (176) hide show
  1. package/.github/actions/lint-css/action.yaml +1 -3
  2. package/.release-it.json +2 -1
  3. package/dist/cli.js +3 -3
  4. package/dist/wysiwyg.css +24 -25
  5. package/dist/wysiwyg.mjs +641 -618
  6. package/jest.config.js +3 -0
  7. package/lib/components/base/Modal.vue +21 -2
  8. package/lib/components/base/__tests__/Modal.test.js +1 -0
  9. package/lib/components/toolbar/controls/link/LinkControl.vue +22 -10
  10. package/lib/components/toolbar/controls/link/LinkControlHeader.vue +3 -3
  11. package/lib/components/toolbar/controls/link/__tests__/LinkControl.test.js +8 -8
  12. package/lib/components/toolbar/controls/link/__tests__/LinkControlHeader.test.js +1 -1
  13. package/lib/components/toolbar/controls/link/composables/useLink.js +10 -6
  14. package/lib/composables/__tests__/__snapshots__/useEditor.test.js.snap +1 -1
  15. package/lib/composables/useEditor.js +4 -3
  16. package/lib/enums/TextSettings.js +2 -0
  17. package/lib/extensions/FontStyle.js +2 -2
  18. package/lib/extensions/FontWeight.js +2 -0
  19. package/lib/extensions/Link.js +13 -15
  20. package/lib/extensions/StylePreset.js +33 -3
  21. package/lib/extensions/TextDecoration.js +6 -12
  22. package/lib/extensions/__tests__/FontFamily.test.js +7 -6
  23. package/lib/extensions/__tests__/FontWeight.test.js +19 -10
  24. package/lib/extensions/__tests__/StylePreset.test.js +52 -2
  25. package/lib/extensions/__tests__/TextDecoration.test.js +11 -40
  26. package/lib/extensions/__tests__/__snapshots__/Alignment.test.js.snap +2 -2
  27. package/lib/extensions/__tests__/__snapshots__/BackgroundColor.test.js.snap +1 -1
  28. package/lib/extensions/__tests__/__snapshots__/FontColor.test.js.snap +1 -1
  29. package/lib/extensions/__tests__/__snapshots__/FontFamily.test.js.snap +19 -1
  30. package/lib/extensions/__tests__/__snapshots__/FontSize.test.js.snap +2 -2
  31. package/lib/extensions/__tests__/__snapshots__/FontStyle.test.js.snap +17 -1
  32. package/lib/extensions/__tests__/__snapshots__/FontWeight.test.js.snap +26 -1
  33. package/lib/extensions/__tests__/__snapshots__/LineHeight.test.js.snap +2 -2
  34. package/lib/extensions/__tests__/__snapshots__/Margin.test.js.snap +2 -2
  35. package/lib/extensions/__tests__/__snapshots__/StylePreset.test.js.snap +22 -2
  36. package/lib/extensions/__tests__/__snapshots__/TextDecoration.test.js.snap +3 -46
  37. package/package.json +22 -22
  38. package/lib/components/toolbar/controls/link/LinkControlApply.vue +0 -35
  39. package/node_modules_lambda/acorn-globals/node_modules/.bin/acorn +0 -4
  40. package/node_modules_lambda/acorn-globals/node_modules/acorn/CHANGELOG.md +0 -620
  41. package/node_modules_lambda/acorn-globals/node_modules/acorn/LICENSE +0 -21
  42. package/node_modules_lambda/acorn-globals/node_modules/acorn/README.md +0 -269
  43. package/node_modules_lambda/acorn-globals/node_modules/acorn/bin/acorn +0 -4
  44. package/node_modules_lambda/acorn-globals/node_modules/acorn/dist/acorn.d.ts +0 -209
  45. package/node_modules_lambda/acorn-globals/node_modules/acorn/dist/acorn.js +0 -5186
  46. package/node_modules_lambda/acorn-globals/node_modules/acorn/dist/acorn.js.map +0 -1
  47. package/node_modules_lambda/acorn-globals/node_modules/acorn/dist/acorn.mjs +0 -5155
  48. package/node_modules_lambda/acorn-globals/node_modules/acorn/dist/acorn.mjs.d.ts +0 -2
  49. package/node_modules_lambda/acorn-globals/node_modules/acorn/dist/acorn.mjs.map +0 -1
  50. package/node_modules_lambda/acorn-globals/node_modules/acorn/dist/bin.js +0 -64
  51. package/node_modules_lambda/acorn-globals/node_modules/acorn/package.json +0 -35
  52. package/node_modules_lambda/cssstyle/node_modules/cssom/LICENSE.txt +0 -20
  53. package/node_modules_lambda/cssstyle/node_modules/cssom/README.mdown +0 -67
  54. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSDocumentRule.js +0 -39
  55. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSFontFaceRule.js +0 -36
  56. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSHostRule.js +0 -37
  57. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSImportRule.js +0 -132
  58. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSKeyframeRule.js +0 -37
  59. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSKeyframesRule.js +0 -39
  60. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSMediaRule.js +0 -41
  61. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSOM.js +0 -3
  62. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSRule.js +0 -43
  63. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSStyleDeclaration.js +0 -148
  64. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSStyleRule.js +0 -190
  65. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSStyleSheet.js +0 -88
  66. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSSupportsRule.js +0 -36
  67. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSValue.js +0 -43
  68. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSValueExpression.js +0 -344
  69. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/MatcherList.js +0 -62
  70. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/MediaList.js +0 -61
  71. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/StyleSheet.js +0 -17
  72. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/clone.js +0 -82
  73. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/index.js +0 -21
  74. package/node_modules_lambda/cssstyle/node_modules/cssom/lib/parse.js +0 -464
  75. package/node_modules_lambda/cssstyle/node_modules/cssom/package.json +0 -18
  76. package/node_modules_lambda/data-urls/node_modules/whatwg-url/LICENSE.txt +0 -21
  77. package/node_modules_lambda/data-urls/node_modules/whatwg-url/README.md +0 -106
  78. package/node_modules_lambda/data-urls/node_modules/whatwg-url/index.js +0 -27
  79. package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/Function.js +0 -42
  80. package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/URL-impl.js +0 -209
  81. package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/URL.js +0 -442
  82. package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/URLSearchParams-impl.js +0 -130
  83. package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/URLSearchParams.js +0 -472
  84. package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/VoidFunction.js +0 -26
  85. package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/encoding.js +0 -16
  86. package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/infra.js +0 -26
  87. package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/percent-encoding.js +0 -142
  88. package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/url-state-machine.js +0 -1244
  89. package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/urlencoded.js +0 -106
  90. package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/utils.js +0 -190
  91. package/node_modules_lambda/data-urls/node_modules/whatwg-url/package.json +0 -58
  92. package/node_modules_lambda/data-urls/node_modules/whatwg-url/webidl2js-wrapper.js +0 -7
  93. package/node_modules_lambda/escodegen/node_modules/estraverse/.jshintrc +0 -16
  94. package/node_modules_lambda/escodegen/node_modules/estraverse/LICENSE.BSD +0 -19
  95. package/node_modules_lambda/escodegen/node_modules/estraverse/README.md +0 -153
  96. package/node_modules_lambda/escodegen/node_modules/estraverse/estraverse.js +0 -805
  97. package/node_modules_lambda/escodegen/node_modules/estraverse/gulpfile.js +0 -70
  98. package/node_modules_lambda/escodegen/node_modules/estraverse/package.json +0 -40
  99. package/node_modules_lambda/escodegen/node_modules/levn/LICENSE +0 -22
  100. package/node_modules_lambda/escodegen/node_modules/levn/README.md +0 -196
  101. package/node_modules_lambda/escodegen/node_modules/levn/lib/cast.js +0 -298
  102. package/node_modules_lambda/escodegen/node_modules/levn/lib/coerce.js +0 -285
  103. package/node_modules_lambda/escodegen/node_modules/levn/lib/index.js +0 -22
  104. package/node_modules_lambda/escodegen/node_modules/levn/lib/parse-string.js +0 -113
  105. package/node_modules_lambda/escodegen/node_modules/levn/lib/parse.js +0 -102
  106. package/node_modules_lambda/escodegen/node_modules/levn/package.json +0 -47
  107. package/node_modules_lambda/escodegen/node_modules/optionator/CHANGELOG.md +0 -56
  108. package/node_modules_lambda/escodegen/node_modules/optionator/LICENSE +0 -22
  109. package/node_modules_lambda/escodegen/node_modules/optionator/README.md +0 -238
  110. package/node_modules_lambda/escodegen/node_modules/optionator/lib/help.js +0 -260
  111. package/node_modules_lambda/escodegen/node_modules/optionator/lib/index.js +0 -465
  112. package/node_modules_lambda/escodegen/node_modules/optionator/lib/util.js +0 -54
  113. package/node_modules_lambda/escodegen/node_modules/optionator/package.json +0 -44
  114. package/node_modules_lambda/escodegen/node_modules/prelude-ls/CHANGELOG.md +0 -99
  115. package/node_modules_lambda/escodegen/node_modules/prelude-ls/LICENSE +0 -22
  116. package/node_modules_lambda/escodegen/node_modules/prelude-ls/README.md +0 -15
  117. package/node_modules_lambda/escodegen/node_modules/prelude-ls/lib/Func.js +0 -65
  118. package/node_modules_lambda/escodegen/node_modules/prelude-ls/lib/List.js +0 -686
  119. package/node_modules_lambda/escodegen/node_modules/prelude-ls/lib/Num.js +0 -130
  120. package/node_modules_lambda/escodegen/node_modules/prelude-ls/lib/Obj.js +0 -154
  121. package/node_modules_lambda/escodegen/node_modules/prelude-ls/lib/Str.js +0 -92
  122. package/node_modules_lambda/escodegen/node_modules/prelude-ls/lib/index.js +0 -178
  123. package/node_modules_lambda/escodegen/node_modules/prelude-ls/package.json +0 -52
  124. package/node_modules_lambda/escodegen/node_modules/source-map/CHANGELOG.md +0 -301
  125. package/node_modules_lambda/escodegen/node_modules/source-map/LICENSE +0 -28
  126. package/node_modules_lambda/escodegen/node_modules/source-map/README.md +0 -742
  127. package/node_modules_lambda/escodegen/node_modules/source-map/dist/source-map.debug.js +0 -3234
  128. package/node_modules_lambda/escodegen/node_modules/source-map/dist/source-map.js +0 -3233
  129. package/node_modules_lambda/escodegen/node_modules/source-map/dist/source-map.min.js +0 -2
  130. package/node_modules_lambda/escodegen/node_modules/source-map/dist/source-map.min.js.map +0 -1
  131. package/node_modules_lambda/escodegen/node_modules/source-map/lib/array-set.js +0 -121
  132. package/node_modules_lambda/escodegen/node_modules/source-map/lib/base64-vlq.js +0 -140
  133. package/node_modules_lambda/escodegen/node_modules/source-map/lib/base64.js +0 -67
  134. package/node_modules_lambda/escodegen/node_modules/source-map/lib/binary-search.js +0 -111
  135. package/node_modules_lambda/escodegen/node_modules/source-map/lib/mapping-list.js +0 -79
  136. package/node_modules_lambda/escodegen/node_modules/source-map/lib/quick-sort.js +0 -114
  137. package/node_modules_lambda/escodegen/node_modules/source-map/lib/source-map-consumer.js +0 -1145
  138. package/node_modules_lambda/escodegen/node_modules/source-map/lib/source-map-generator.js +0 -425
  139. package/node_modules_lambda/escodegen/node_modules/source-map/lib/source-node.js +0 -413
  140. package/node_modules_lambda/escodegen/node_modules/source-map/lib/util.js +0 -488
  141. package/node_modules_lambda/escodegen/node_modules/source-map/package.json +0 -73
  142. package/node_modules_lambda/escodegen/node_modules/source-map/source-map.d.ts +0 -98
  143. package/node_modules_lambda/escodegen/node_modules/source-map/source-map.js +0 -8
  144. package/node_modules_lambda/escodegen/node_modules/type-check/LICENSE +0 -22
  145. package/node_modules_lambda/escodegen/node_modules/type-check/README.md +0 -210
  146. package/node_modules_lambda/escodegen/node_modules/type-check/lib/check.js +0 -126
  147. package/node_modules_lambda/escodegen/node_modules/type-check/lib/index.js +0 -16
  148. package/node_modules_lambda/escodegen/node_modules/type-check/lib/parse-type.js +0 -196
  149. package/node_modules_lambda/escodegen/node_modules/type-check/package.json +0 -40
  150. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/.github/dependabot.yml +0 -11
  151. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/Changelog.md +0 -212
  152. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/LICENSE +0 -21
  153. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/README.md +0 -130
  154. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/dbcs-codec.js +0 -597
  155. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/dbcs-data.js +0 -188
  156. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/index.js +0 -23
  157. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/internal.js +0 -198
  158. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/sbcs-codec.js +0 -72
  159. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/sbcs-data-generated.js +0 -451
  160. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/sbcs-data.js +0 -179
  161. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/tables/big5-added.json +0 -122
  162. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/tables/cp936.json +0 -264
  163. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/tables/cp949.json +0 -273
  164. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/tables/cp950.json +0 -177
  165. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/tables/eucjp.json +0 -182
  166. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/tables/gb18030-ranges.json +0 -1
  167. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/tables/gbk-added.json +0 -56
  168. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/tables/shiftjis.json +0 -125
  169. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/utf16.js +0 -197
  170. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/utf32.js +0 -319
  171. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/utf7.js +0 -290
  172. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/lib/bom-handling.js +0 -52
  173. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/lib/index.d.ts +0 -41
  174. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/lib/index.js +0 -180
  175. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/lib/streams.js +0 -109
  176. package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/package.json +0 -44
@@ -1,197 +0,0 @@
1
- "use strict";
2
- var Buffer = require("safer-buffer").Buffer;
3
-
4
- // Note: UTF16-LE (or UCS2) codec is Node.js native. See encodings/internal.js
5
-
6
- // == UTF16-BE codec. ==========================================================
7
-
8
- exports.utf16be = Utf16BECodec;
9
- function Utf16BECodec() {
10
- }
11
-
12
- Utf16BECodec.prototype.encoder = Utf16BEEncoder;
13
- Utf16BECodec.prototype.decoder = Utf16BEDecoder;
14
- Utf16BECodec.prototype.bomAware = true;
15
-
16
-
17
- // -- Encoding
18
-
19
- function Utf16BEEncoder() {
20
- }
21
-
22
- Utf16BEEncoder.prototype.write = function(str) {
23
- var buf = Buffer.from(str, 'ucs2');
24
- for (var i = 0; i < buf.length; i += 2) {
25
- var tmp = buf[i]; buf[i] = buf[i+1]; buf[i+1] = tmp;
26
- }
27
- return buf;
28
- }
29
-
30
- Utf16BEEncoder.prototype.end = function() {
31
- }
32
-
33
-
34
- // -- Decoding
35
-
36
- function Utf16BEDecoder() {
37
- this.overflowByte = -1;
38
- }
39
-
40
- Utf16BEDecoder.prototype.write = function(buf) {
41
- if (buf.length == 0)
42
- return '';
43
-
44
- var buf2 = Buffer.alloc(buf.length + 1),
45
- i = 0, j = 0;
46
-
47
- if (this.overflowByte !== -1) {
48
- buf2[0] = buf[0];
49
- buf2[1] = this.overflowByte;
50
- i = 1; j = 2;
51
- }
52
-
53
- for (; i < buf.length-1; i += 2, j+= 2) {
54
- buf2[j] = buf[i+1];
55
- buf2[j+1] = buf[i];
56
- }
57
-
58
- this.overflowByte = (i == buf.length-1) ? buf[buf.length-1] : -1;
59
-
60
- return buf2.slice(0, j).toString('ucs2');
61
- }
62
-
63
- Utf16BEDecoder.prototype.end = function() {
64
- this.overflowByte = -1;
65
- }
66
-
67
-
68
- // == UTF-16 codec =============================================================
69
- // Decoder chooses automatically from UTF-16LE and UTF-16BE using BOM and space-based heuristic.
70
- // Defaults to UTF-16LE, as it's prevalent and default in Node.
71
- // http://en.wikipedia.org/wiki/UTF-16 and http://encoding.spec.whatwg.org/#utf-16le
72
- // Decoder default can be changed: iconv.decode(buf, 'utf16', {defaultEncoding: 'utf-16be'});
73
-
74
- // Encoder uses UTF-16LE and prepends BOM (which can be overridden with addBOM: false).
75
-
76
- exports.utf16 = Utf16Codec;
77
- function Utf16Codec(codecOptions, iconv) {
78
- this.iconv = iconv;
79
- }
80
-
81
- Utf16Codec.prototype.encoder = Utf16Encoder;
82
- Utf16Codec.prototype.decoder = Utf16Decoder;
83
-
84
-
85
- // -- Encoding (pass-through)
86
-
87
- function Utf16Encoder(options, codec) {
88
- options = options || {};
89
- if (options.addBOM === undefined)
90
- options.addBOM = true;
91
- this.encoder = codec.iconv.getEncoder('utf-16le', options);
92
- }
93
-
94
- Utf16Encoder.prototype.write = function(str) {
95
- return this.encoder.write(str);
96
- }
97
-
98
- Utf16Encoder.prototype.end = function() {
99
- return this.encoder.end();
100
- }
101
-
102
-
103
- // -- Decoding
104
-
105
- function Utf16Decoder(options, codec) {
106
- this.decoder = null;
107
- this.initialBufs = [];
108
- this.initialBufsLen = 0;
109
-
110
- this.options = options || {};
111
- this.iconv = codec.iconv;
112
- }
113
-
114
- Utf16Decoder.prototype.write = function(buf) {
115
- if (!this.decoder) {
116
- // Codec is not chosen yet. Accumulate initial bytes.
117
- this.initialBufs.push(buf);
118
- this.initialBufsLen += buf.length;
119
-
120
- if (this.initialBufsLen < 16) // We need more bytes to use space heuristic (see below)
121
- return '';
122
-
123
- // We have enough bytes -> detect endianness.
124
- var encoding = detectEncoding(this.initialBufs, this.options.defaultEncoding);
125
- this.decoder = this.iconv.getDecoder(encoding, this.options);
126
-
127
- var resStr = '';
128
- for (var i = 0; i < this.initialBufs.length; i++)
129
- resStr += this.decoder.write(this.initialBufs[i]);
130
-
131
- this.initialBufs.length = this.initialBufsLen = 0;
132
- return resStr;
133
- }
134
-
135
- return this.decoder.write(buf);
136
- }
137
-
138
- Utf16Decoder.prototype.end = function() {
139
- if (!this.decoder) {
140
- var encoding = detectEncoding(this.initialBufs, this.options.defaultEncoding);
141
- this.decoder = this.iconv.getDecoder(encoding, this.options);
142
-
143
- var resStr = '';
144
- for (var i = 0; i < this.initialBufs.length; i++)
145
- resStr += this.decoder.write(this.initialBufs[i]);
146
-
147
- var trail = this.decoder.end();
148
- if (trail)
149
- resStr += trail;
150
-
151
- this.initialBufs.length = this.initialBufsLen = 0;
152
- return resStr;
153
- }
154
- return this.decoder.end();
155
- }
156
-
157
- function detectEncoding(bufs, defaultEncoding) {
158
- var b = [];
159
- var charsProcessed = 0;
160
- var asciiCharsLE = 0, asciiCharsBE = 0; // Number of ASCII chars when decoded as LE or BE.
161
-
162
- outer_loop:
163
- for (var i = 0; i < bufs.length; i++) {
164
- var buf = bufs[i];
165
- for (var j = 0; j < buf.length; j++) {
166
- b.push(buf[j]);
167
- if (b.length === 2) {
168
- if (charsProcessed === 0) {
169
- // Check BOM first.
170
- if (b[0] === 0xFF && b[1] === 0xFE) return 'utf-16le';
171
- if (b[0] === 0xFE && b[1] === 0xFF) return 'utf-16be';
172
- }
173
-
174
- if (b[0] === 0 && b[1] !== 0) asciiCharsBE++;
175
- if (b[0] !== 0 && b[1] === 0) asciiCharsLE++;
176
-
177
- b.length = 0;
178
- charsProcessed++;
179
-
180
- if (charsProcessed >= 100) {
181
- break outer_loop;
182
- }
183
- }
184
- }
185
- }
186
-
187
- // Make decisions.
188
- // Most of the time, the content has ASCII chars (U+00**), but the opposite (U+**00) is uncommon.
189
- // So, we count ASCII as if it was LE or BE, and decide from that.
190
- if (asciiCharsBE > asciiCharsLE) return 'utf-16be';
191
- if (asciiCharsBE < asciiCharsLE) return 'utf-16le';
192
-
193
- // Couldn't decide (likely all zeros or not enough data).
194
- return defaultEncoding || 'utf-16le';
195
- }
196
-
197
-
@@ -1,319 +0,0 @@
1
- 'use strict';
2
-
3
- var Buffer = require('safer-buffer').Buffer;
4
-
5
- // == UTF32-LE/BE codec. ==========================================================
6
-
7
- exports._utf32 = Utf32Codec;
8
-
9
- function Utf32Codec(codecOptions, iconv) {
10
- this.iconv = iconv;
11
- this.bomAware = true;
12
- this.isLE = codecOptions.isLE;
13
- }
14
-
15
- exports.utf32le = { type: '_utf32', isLE: true };
16
- exports.utf32be = { type: '_utf32', isLE: false };
17
-
18
- // Aliases
19
- exports.ucs4le = 'utf32le';
20
- exports.ucs4be = 'utf32be';
21
-
22
- Utf32Codec.prototype.encoder = Utf32Encoder;
23
- Utf32Codec.prototype.decoder = Utf32Decoder;
24
-
25
- // -- Encoding
26
-
27
- function Utf32Encoder(options, codec) {
28
- this.isLE = codec.isLE;
29
- this.highSurrogate = 0;
30
- }
31
-
32
- Utf32Encoder.prototype.write = function(str) {
33
- var src = Buffer.from(str, 'ucs2');
34
- var dst = Buffer.alloc(src.length * 2);
35
- var write32 = this.isLE ? dst.writeUInt32LE : dst.writeUInt32BE;
36
- var offset = 0;
37
-
38
- for (var i = 0; i < src.length; i += 2) {
39
- var code = src.readUInt16LE(i);
40
- var isHighSurrogate = (0xD800 <= code && code < 0xDC00);
41
- var isLowSurrogate = (0xDC00 <= code && code < 0xE000);
42
-
43
- if (this.highSurrogate) {
44
- if (isHighSurrogate || !isLowSurrogate) {
45
- // There shouldn't be two high surrogates in a row, nor a high surrogate which isn't followed by a low
46
- // surrogate. If this happens, keep the pending high surrogate as a stand-alone semi-invalid character
47
- // (technically wrong, but expected by some applications, like Windows file names).
48
- write32.call(dst, this.highSurrogate, offset);
49
- offset += 4;
50
- }
51
- else {
52
- // Create 32-bit value from high and low surrogates;
53
- var codepoint = (((this.highSurrogate - 0xD800) << 10) | (code - 0xDC00)) + 0x10000;
54
-
55
- write32.call(dst, codepoint, offset);
56
- offset += 4;
57
- this.highSurrogate = 0;
58
-
59
- continue;
60
- }
61
- }
62
-
63
- if (isHighSurrogate)
64
- this.highSurrogate = code;
65
- else {
66
- // Even if the current character is a low surrogate, with no previous high surrogate, we'll
67
- // encode it as a semi-invalid stand-alone character for the same reasons expressed above for
68
- // unpaired high surrogates.
69
- write32.call(dst, code, offset);
70
- offset += 4;
71
- this.highSurrogate = 0;
72
- }
73
- }
74
-
75
- if (offset < dst.length)
76
- dst = dst.slice(0, offset);
77
-
78
- return dst;
79
- };
80
-
81
- Utf32Encoder.prototype.end = function() {
82
- // Treat any leftover high surrogate as a semi-valid independent character.
83
- if (!this.highSurrogate)
84
- return;
85
-
86
- var buf = Buffer.alloc(4);
87
-
88
- if (this.isLE)
89
- buf.writeUInt32LE(this.highSurrogate, 0);
90
- else
91
- buf.writeUInt32BE(this.highSurrogate, 0);
92
-
93
- this.highSurrogate = 0;
94
-
95
- return buf;
96
- };
97
-
98
- // -- Decoding
99
-
100
- function Utf32Decoder(options, codec) {
101
- this.isLE = codec.isLE;
102
- this.badChar = codec.iconv.defaultCharUnicode.charCodeAt(0);
103
- this.overflow = [];
104
- }
105
-
106
- Utf32Decoder.prototype.write = function(src) {
107
- if (src.length === 0)
108
- return '';
109
-
110
- var i = 0;
111
- var codepoint = 0;
112
- var dst = Buffer.alloc(src.length + 4);
113
- var offset = 0;
114
- var isLE = this.isLE;
115
- var overflow = this.overflow;
116
- var badChar = this.badChar;
117
-
118
- if (overflow.length > 0) {
119
- for (; i < src.length && overflow.length < 4; i++)
120
- overflow.push(src[i]);
121
-
122
- if (overflow.length === 4) {
123
- // NOTE: codepoint is a signed int32 and can be negative.
124
- // NOTE: We copied this block from below to help V8 optimize it (it works with array, not buffer).
125
- if (isLE) {
126
- codepoint = overflow[i] | (overflow[i+1] << 8) | (overflow[i+2] << 16) | (overflow[i+3] << 24);
127
- } else {
128
- codepoint = overflow[i+3] | (overflow[i+2] << 8) | (overflow[i+1] << 16) | (overflow[i] << 24);
129
- }
130
- overflow.length = 0;
131
-
132
- offset = _writeCodepoint(dst, offset, codepoint, badChar);
133
- }
134
- }
135
-
136
- // Main loop. Should be as optimized as possible.
137
- for (; i < src.length - 3; i += 4) {
138
- // NOTE: codepoint is a signed int32 and can be negative.
139
- if (isLE) {
140
- codepoint = src[i] | (src[i+1] << 8) | (src[i+2] << 16) | (src[i+3] << 24);
141
- } else {
142
- codepoint = src[i+3] | (src[i+2] << 8) | (src[i+1] << 16) | (src[i] << 24);
143
- }
144
- offset = _writeCodepoint(dst, offset, codepoint, badChar);
145
- }
146
-
147
- // Keep overflowing bytes.
148
- for (; i < src.length; i++) {
149
- overflow.push(src[i]);
150
- }
151
-
152
- return dst.slice(0, offset).toString('ucs2');
153
- };
154
-
155
- function _writeCodepoint(dst, offset, codepoint, badChar) {
156
- // NOTE: codepoint is signed int32 and can be negative. We keep it that way to help V8 with optimizations.
157
- if (codepoint < 0 || codepoint > 0x10FFFF) {
158
- // Not a valid Unicode codepoint
159
- codepoint = badChar;
160
- }
161
-
162
- // Ephemeral Planes: Write high surrogate.
163
- if (codepoint >= 0x10000) {
164
- codepoint -= 0x10000;
165
-
166
- var high = 0xD800 | (codepoint >> 10);
167
- dst[offset++] = high & 0xff;
168
- dst[offset++] = high >> 8;
169
-
170
- // Low surrogate is written below.
171
- var codepoint = 0xDC00 | (codepoint & 0x3FF);
172
- }
173
-
174
- // Write BMP char or low surrogate.
175
- dst[offset++] = codepoint & 0xff;
176
- dst[offset++] = codepoint >> 8;
177
-
178
- return offset;
179
- };
180
-
181
- Utf32Decoder.prototype.end = function() {
182
- this.overflow.length = 0;
183
- };
184
-
185
- // == UTF-32 Auto codec =============================================================
186
- // Decoder chooses automatically from UTF-32LE and UTF-32BE using BOM and space-based heuristic.
187
- // Defaults to UTF-32LE. http://en.wikipedia.org/wiki/UTF-32
188
- // Encoder/decoder default can be changed: iconv.decode(buf, 'utf32', {defaultEncoding: 'utf-32be'});
189
-
190
- // Encoder prepends BOM (which can be overridden with (addBOM: false}).
191
-
192
- exports.utf32 = Utf32AutoCodec;
193
- exports.ucs4 = 'utf32';
194
-
195
- function Utf32AutoCodec(options, iconv) {
196
- this.iconv = iconv;
197
- }
198
-
199
- Utf32AutoCodec.prototype.encoder = Utf32AutoEncoder;
200
- Utf32AutoCodec.prototype.decoder = Utf32AutoDecoder;
201
-
202
- // -- Encoding
203
-
204
- function Utf32AutoEncoder(options, codec) {
205
- options = options || {};
206
-
207
- if (options.addBOM === undefined)
208
- options.addBOM = true;
209
-
210
- this.encoder = codec.iconv.getEncoder(options.defaultEncoding || 'utf-32le', options);
211
- }
212
-
213
- Utf32AutoEncoder.prototype.write = function(str) {
214
- return this.encoder.write(str);
215
- };
216
-
217
- Utf32AutoEncoder.prototype.end = function() {
218
- return this.encoder.end();
219
- };
220
-
221
- // -- Decoding
222
-
223
- function Utf32AutoDecoder(options, codec) {
224
- this.decoder = null;
225
- this.initialBufs = [];
226
- this.initialBufsLen = 0;
227
- this.options = options || {};
228
- this.iconv = codec.iconv;
229
- }
230
-
231
- Utf32AutoDecoder.prototype.write = function(buf) {
232
- if (!this.decoder) {
233
- // Codec is not chosen yet. Accumulate initial bytes.
234
- this.initialBufs.push(buf);
235
- this.initialBufsLen += buf.length;
236
-
237
- if (this.initialBufsLen < 32) // We need more bytes to use space heuristic (see below)
238
- return '';
239
-
240
- // We have enough bytes -> detect endianness.
241
- var encoding = detectEncoding(this.initialBufs, this.options.defaultEncoding);
242
- this.decoder = this.iconv.getDecoder(encoding, this.options);
243
-
244
- var resStr = '';
245
- for (var i = 0; i < this.initialBufs.length; i++)
246
- resStr += this.decoder.write(this.initialBufs[i]);
247
-
248
- this.initialBufs.length = this.initialBufsLen = 0;
249
- return resStr;
250
- }
251
-
252
- return this.decoder.write(buf);
253
- };
254
-
255
- Utf32AutoDecoder.prototype.end = function() {
256
- if (!this.decoder) {
257
- var encoding = detectEncoding(this.initialBufs, this.options.defaultEncoding);
258
- this.decoder = this.iconv.getDecoder(encoding, this.options);
259
-
260
- var resStr = '';
261
- for (var i = 0; i < this.initialBufs.length; i++)
262
- resStr += this.decoder.write(this.initialBufs[i]);
263
-
264
- var trail = this.decoder.end();
265
- if (trail)
266
- resStr += trail;
267
-
268
- this.initialBufs.length = this.initialBufsLen = 0;
269
- return resStr;
270
- }
271
-
272
- return this.decoder.end();
273
- };
274
-
275
- function detectEncoding(bufs, defaultEncoding) {
276
- var b = [];
277
- var charsProcessed = 0;
278
- var invalidLE = 0, invalidBE = 0; // Number of invalid chars when decoded as LE or BE.
279
- var bmpCharsLE = 0, bmpCharsBE = 0; // Number of BMP chars when decoded as LE or BE.
280
-
281
- outer_loop:
282
- for (var i = 0; i < bufs.length; i++) {
283
- var buf = bufs[i];
284
- for (var j = 0; j < buf.length; j++) {
285
- b.push(buf[j]);
286
- if (b.length === 4) {
287
- if (charsProcessed === 0) {
288
- // Check BOM first.
289
- if (b[0] === 0xFF && b[1] === 0xFE && b[2] === 0 && b[3] === 0) {
290
- return 'utf-32le';
291
- }
292
- if (b[0] === 0 && b[1] === 0 && b[2] === 0xFE && b[3] === 0xFF) {
293
- return 'utf-32be';
294
- }
295
- }
296
-
297
- if (b[0] !== 0 || b[1] > 0x10) invalidBE++;
298
- if (b[3] !== 0 || b[2] > 0x10) invalidLE++;
299
-
300
- if (b[0] === 0 && b[1] === 0 && (b[2] !== 0 || b[3] !== 0)) bmpCharsBE++;
301
- if ((b[0] !== 0 || b[1] !== 0) && b[2] === 0 && b[3] === 0) bmpCharsLE++;
302
-
303
- b.length = 0;
304
- charsProcessed++;
305
-
306
- if (charsProcessed >= 100) {
307
- break outer_loop;
308
- }
309
- }
310
- }
311
- }
312
-
313
- // Make decisions.
314
- if (bmpCharsBE - invalidBE > bmpCharsLE - invalidLE) return 'utf-32be';
315
- if (bmpCharsBE - invalidBE < bmpCharsLE - invalidLE) return 'utf-32le';
316
-
317
- // Couldn't decide (likely all zeros or not enough data).
318
- return defaultEncoding || 'utf-32le';
319
- }