@yltrcc/vditor 0.1.1 → 0.3.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.
@@ -1,270 +1,314 @@
1
- .vditor-wysiwyg {
2
- box-sizing: border-box;
3
- flex: 1;
4
- position: relative;
5
- width: 100%;
6
- min-width: 1px;
7
-
8
- pre.vditor-reset {
9
- background-color: var(--panel-background-color);
10
- margin: 0;
11
- white-space: pre-wrap;
12
- height: 100%;
13
- box-sizing: border-box;
14
-
15
- &[contenteditable="false"] {
16
- opacity: 0.3;
17
- cursor: not-allowed;
18
- }
19
-
20
- &:empty::before {
21
- content: attr(placeholder);
22
- color: var(--second-color);
23
- }
24
-
25
- &:focus {
26
- outline: none;
27
- background-color: var(--textarea-background-color);
28
- }
29
-
30
- &:after {
31
- content: "";
32
- height: var(--editor-bottom);
33
- display: block;
34
- }
35
- }
36
-
37
- blockquote:empty::before,
38
- pre > code:empty::before,
39
- p:empty::before,
40
- h1:empty::after,
41
- h2:empty::after,
42
- h3:empty::after,
43
- h4:empty::after,
44
- h5:empty::after,
45
- h6:empty::after {
46
- content: ' ';
47
- }
48
-
49
- code[data-marker="`"] {
50
- padding-left: 0 !important;
51
- padding-right: 0 !important;
52
- }
53
-
54
- &__block {
55
- position: relative;
56
-
57
- // 编辑区域 - 默认隐藏
58
- pre:first-child {
59
- margin-bottom: -1em;
60
- display: none; // 默认隐藏编辑区域
61
-
62
- code {
63
- height: auto;
64
- color: var(--textarea-text-color);
65
- height: auto;
66
- text-align: left;
67
- }
68
- }
69
-
70
- pre:last-child {
71
- margin-bottom: 1em;
72
- }
73
-
74
- // 当处于编辑状态时显示编辑区域,隐藏预览区域
75
- &--editing {
76
- pre:first-child {
77
- display: block;
78
- }
79
-
80
- .vditor-wysiwyg__preview {
81
- display: none;
82
- }
83
- }
84
- }
85
-
86
- &__preview {
87
- cursor: pointer;
88
- white-space: initial;
89
- min-height: 27px;
90
- display: block; // 默认显示预览区域
91
-
92
- // 代码块预览样式优化
93
- pre {
94
- margin: 0;
95
- padding: 1em;
96
- background-color: var(--code-background-color);
97
- border-radius: 4px;
98
- overflow-x: auto;
99
-
100
- code {
101
- font-family: var(--code-font-family);
102
- font-size: var(--code-font-size);
103
- line-height: var(--code-line-height);
104
- }
105
- }
106
-
107
- // 语言标签
108
- &::before {
109
- content: attr(data-language);
110
- position: absolute;
111
- top: 0;
112
- right: 0;
113
- padding: 2px 8px;
114
- font-size: 12px;
115
- color: var(--second-color);
116
- background-color: var(--panel-background-color);
117
- border-radius: 0 4px 0 4px;
118
- }
119
-
120
- &:hover {
121
- box-shadow: 0 0 0 2px var(--blurColor);
122
- }
123
- }
124
-
125
- & > .vditor-reset > h1:before,
126
- & > .vditor-reset > h2:before,
127
- & > .vditor-reset > h3:before,
128
- & > .vditor-reset > h4:before,
129
- & > .vditor-reset > h5:before,
130
- & > .vditor-reset > h6:before,
131
- div.vditor-wysiwyg__block:before,
132
- div[data-type="link-ref-defs-block"]:before,
133
- div[data-type="footnotes-block"]:before,
134
- .vditor-toc:before {
135
- float: left;
136
- padding-right: 4px;
137
- margin-left: -29px;
138
- content: 'H1';
139
- font-size: 0.85rem;
140
- font-weight: normal;
141
- color: var(--second-color);
142
- }
143
-
144
- & > .vditor-reset > h2:before {
145
- content: 'H2';
146
- }
147
-
148
- & > .vditor-reset > h3:before {
149
- content: 'H3';
150
- }
151
-
152
- & > .vditor-reset > h4:before {
153
- content: 'H4';
154
- }
155
-
156
- & > .vditor-reset > h5:before {
157
- content: 'H5';
158
- }
159
-
160
- & > .vditor-reset > h6:before {
161
- content: 'H6';
162
- }
163
-
164
- div[data-type="link-ref-defs-block"]:before {
165
- content: '"A"';
166
- }
167
-
168
- div[data-type="footnotes-block"]:before {
169
- content: '^F';
170
- }
171
-
172
- div.vditor-wysiwyg__block:before {
173
- content: "</>";
174
- }
175
-
176
- div.vditor-wysiwyg__block[data-type="yaml-front-matter"]:before {
177
- content: "F";
178
- }
179
-
180
- div.vditor-wysiwyg__block[data-type="math-block"]:before {
181
- content: "$$";
182
- }
183
-
184
- .vditor-toc:before {
185
- content: "ToC";
186
- }
187
-
188
- hr {
189
- display: inline-block;
190
- margin: 12px 0;
191
- width: 100%;
192
- }
193
-
194
- details {
195
- white-space: initial;
196
- }
197
-
198
- a {
199
- cursor: pointer;
200
- color: @blurColor;
201
- text-decoration: none;
202
- background-color: rgba(66, 133, 244, 0.1);
203
- padding: 2px 4px;
204
- border-radius: 3px;
205
- transition: background-color 0.2s ease;
206
-
207
- &:hover {
208
- background-color: rgba(66, 133, 244, 0.2);
209
- text-decoration: underline;
210
- }
211
-
212
- &:visited {
213
- color: darken(@blurColor, 10%);
214
- }
215
- }
216
-
217
- img {
218
- cursor: pointer;
219
- border: 2px solid transparent;
220
- border-radius: 4px;
221
- transition: border-color 0.2s ease, box-shadow 0.2s ease;
222
-
223
- &:hover {
224
- border-color: @blurColor;
225
- box-shadow: 0 0 8px rgba(66, 133, 244, 0.3);
226
- }
227
- }
228
-
229
- span[data-type="backslash"] > span {
230
- display: none;
231
- color: var(--second-color);
232
- }
233
-
234
- span[data-type="link-ref"],
235
- sup[data-type="footnotes-ref"] {
236
- color: @blurColor;
237
- }
238
-
239
- span[data-type="toc-h"] {
240
- color: @blurColor;
241
- text-decoration: underline;
242
- }
243
-
244
- div[data-type="footnotes-block"] {
245
- border-top: 2px solid var(--heading-border-color);
246
- padding-top: 24px;
247
- margin-top: 24px;
248
- }
249
-
250
- div[data-type="link-ref-defs-block"] {
251
- color: var(--blockquote-color);
252
- }
253
- }
254
-
255
- @media screen and (max-width: @max-width) {
256
- .vditor-wysiwyg {
257
- h1:before,
258
- h2:before,
259
- h3:before,
260
- h4:before,
261
- h5:before,
262
- h6:before,
263
- div.vditor-wysiwyg__block:before,
264
- div[data-type="link-ref-defs-block"]:before,
265
- div[data-type="footnotes-block"]:before,
266
- .vditor-toc:before {
267
- content: none;
268
- }
269
- }
270
- }
1
+ .vditor-wysiwyg {
2
+ box-sizing: border-box;
3
+ flex: 1;
4
+ position: relative;
5
+ width: 100%;
6
+ min-width: 1px;
7
+
8
+ pre.vditor-reset {
9
+ background-color: var(--panel-background-color);
10
+ margin: 0;
11
+ white-space: pre-wrap;
12
+ height: 100%;
13
+ box-sizing: border-box;
14
+
15
+ &[contenteditable="false"] {
16
+ opacity: 0.3;
17
+ cursor: not-allowed;
18
+ }
19
+
20
+ &:empty::before {
21
+ content: attr(placeholder);
22
+ color: var(--second-color);
23
+ }
24
+
25
+ &:focus {
26
+ outline: none;
27
+ background-color: var(--textarea-background-color);
28
+ }
29
+
30
+ &:after {
31
+ content: "";
32
+ height: var(--editor-bottom);
33
+ display: block;
34
+ }
35
+ }
36
+
37
+ blockquote:empty::before,
38
+ pre > code:empty::before,
39
+ p:empty::before,
40
+ h1:empty::after,
41
+ h2:empty::after,
42
+ h3:empty::after,
43
+ h4:empty::after,
44
+ h5:empty::after,
45
+ h6:empty::after {
46
+ content: ' ';
47
+ }
48
+
49
+ code[data-marker="`"] {
50
+ padding-left: 0 !important;
51
+ padding-right: 0 !important;
52
+ }
53
+
54
+ &__block {
55
+ position: relative;
56
+
57
+ // 编辑区域 - 默认隐藏,但保持预览区域的样式
58
+ pre:first-child {
59
+ display: none; // 默认隐藏编辑区域
60
+ position: relative;
61
+ margin: 0;
62
+ padding: 1em;
63
+ background-color: rgba(0, 0, 0, 0.03);
64
+ border-radius: 4px;
65
+ overflow-x: auto;
66
+ cursor: text;
67
+ white-space: initial;
68
+ min-height: 27px;
69
+ background-size: 20px 20px;
70
+ background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAAA8AgMAAABHkjHhAAAACVBMVEWAgIBaWlo+Pj7rTFvWAAAAA3RSTlMHCAw+VhR4AAAA+klEQVQoz4WSMW7EQAhFPxKWNh2FCx+HkaZI6RRb5DYbyVfIJXLKDCFoMbaTKSw/8ZnPAPjaH2xgZcUNUDADD7D9LtDBCLZ45fbkvo/30K8yeI64pPwl6znd/3n/Oe93P3ho9qeh72btTFzqkz0rsJle8Zr81OLEwZ1dv/713uWqvu2pl+k0fy7MWtj9r/tN5q/02z89qa/L4Dc2LvM93kezPfXlME/O86EbY/V9GB9ePX8G1/6W+/9h1dq/HGfTfzT3j/xNo7522Bfnqe5jO/fvhVthlfk434v3iO9zG/UOphyPeinPl1J8Gtaa7xPTa/Dk+RIs4deMvwGvcGsmsCvJ0AAAAABJRU5ErkJggg==);
71
+
72
+ code {
73
+ margin: 0;
74
+ font-family: var(--code-font-family);
75
+ font-size: var(--code-font-size);
76
+ line-height: var(--code-line-height);
77
+ padding: 0;
78
+ background-color: transparent !important;
79
+ border-radius: 0;
80
+ display: inline;
81
+ overflow: visible;
82
+ white-space: pre;
83
+ word-break: initial;
84
+ word-wrap: normal;
85
+ }
86
+
87
+ // 编辑状态下的语言标签
88
+ &::before {
89
+ content: attr(data-language);
90
+ position: absolute;
91
+ top: 0;
92
+ right: 0;
93
+ padding: 2px 8px;
94
+ font-size: 12px;
95
+ color: var(--second-color);
96
+ background-color: var(--panel-background-color);
97
+ border-radius: 0 4px 0 4px;
98
+ z-index: 1;
99
+ }
100
+
101
+ // 编辑状态下也有 hover 效果,保持一致
102
+ &:hover {
103
+ box-shadow: 0 0 0 2px var(--blurColor);
104
+ }
105
+
106
+ // 编辑状态下去掉 outline,保持美观
107
+ &:focus {
108
+ outline: none;
109
+ }
110
+ }
111
+
112
+ pre:last-child {
113
+ margin-bottom: 1em;
114
+ }
115
+
116
+ // 当处于编辑状态时显示编辑区域,隐藏预览区域
117
+ &--editing {
118
+ pre:first-child {
119
+ display: block;
120
+ margin: 0;
121
+ }
122
+
123
+ .vditor-wysiwyg__preview {
124
+ display: none;
125
+ }
126
+ }
127
+ }
128
+
129
+ &__preview {
130
+ cursor: pointer;
131
+ white-space: initial;
132
+ min-height: 27px;
133
+ display: block; // 默认显示预览区域
134
+
135
+ // 代码块预览样式优化
136
+ pre {
137
+ margin: 0;
138
+ padding: 1em;
139
+ background-color: var(--code-background-color);
140
+ border-radius: 4px;
141
+ overflow-x: auto;
142
+
143
+ code {
144
+ font-family: var(--code-font-family);
145
+ font-size: var(--code-font-size);
146
+ line-height: var(--code-line-height);
147
+ background-color: transparent !important;
148
+ }
149
+ }
150
+
151
+ // 语言标签
152
+ &::before {
153
+ content: attr(data-language);
154
+ position: absolute;
155
+ top: 0;
156
+ right: 0;
157
+ padding: 2px 8px;
158
+ font-size: 12px;
159
+ color: var(--second-color);
160
+ background-color: var(--panel-background-color);
161
+ border-radius: 0 4px 0 4px;
162
+ }
163
+
164
+ &:hover {
165
+ box-shadow: 0 0 0 2px var(--blurColor);
166
+ }
167
+ }
168
+
169
+ & > .vditor-reset > h1:before,
170
+ & > .vditor-reset > h2:before,
171
+ & > .vditor-reset > h3:before,
172
+ & > .vditor-reset > h4:before,
173
+ & > .vditor-reset > h5:before,
174
+ & > .vditor-reset > h6:before,
175
+ div.vditor-wysiwyg__block:before,
176
+ div[data-type="link-ref-defs-block"]:before,
177
+ div[data-type="footnotes-block"]:before,
178
+ .vditor-toc:before {
179
+ float: left;
180
+ padding-right: 4px;
181
+ margin-left: -29px;
182
+ content: 'H1';
183
+ font-size: 0.85rem;
184
+ font-weight: normal;
185
+ color: var(--second-color);
186
+ }
187
+
188
+ & > .vditor-reset > h2:before {
189
+ content: 'H2';
190
+ }
191
+
192
+ & > .vditor-reset > h3:before {
193
+ content: 'H3';
194
+ }
195
+
196
+ & > .vditor-reset > h4:before {
197
+ content: 'H4';
198
+ }
199
+
200
+ & > .vditor-reset > h5:before {
201
+ content: 'H5';
202
+ }
203
+
204
+ & > .vditor-reset > h6:before {
205
+ content: 'H6';
206
+ }
207
+
208
+ div[data-type="link-ref-defs-block"]:before {
209
+ content: '"A"';
210
+ }
211
+
212
+ div[data-type="footnotes-block"]:before {
213
+ content: '^F';
214
+ }
215
+
216
+ div.vditor-wysiwyg__block:before {
217
+ content: "</>";
218
+ }
219
+
220
+ div.vditor-wysiwyg__block[data-type="yaml-front-matter"]:before {
221
+ content: "F";
222
+ }
223
+
224
+ div.vditor-wysiwyg__block[data-type="math-block"]:before {
225
+ content: "$$";
226
+ }
227
+
228
+ .vditor-toc:before {
229
+ content: "ToC";
230
+ }
231
+
232
+ hr {
233
+ display: inline-block;
234
+ margin: 12px 0;
235
+ width: 100%;
236
+ }
237
+
238
+ details {
239
+ white-space: initial;
240
+ }
241
+
242
+ a {
243
+ cursor: pointer;
244
+ color: @blurColor;
245
+ text-decoration: none;
246
+ background-color: rgba(66, 133, 244, 0.1);
247
+ padding: 2px 4px;
248
+ border-radius: 3px;
249
+ transition: background-color 0.2s ease;
250
+
251
+ &:hover {
252
+ background-color: rgba(66, 133, 244, 0.2);
253
+ text-decoration: underline;
254
+ }
255
+
256
+ &:visited {
257
+ color: darken(@blurColor, 10%);
258
+ }
259
+ }
260
+
261
+ img {
262
+ cursor: pointer;
263
+ border: 2px solid transparent;
264
+ border-radius: 4px;
265
+ transition: border-color 0.2s ease, box-shadow 0.2s ease;
266
+
267
+ &:hover {
268
+ border-color: @blurColor;
269
+ box-shadow: 0 0 8px rgba(66, 133, 244, 0.3);
270
+ }
271
+ }
272
+
273
+ span[data-type="backslash"] > span {
274
+ display: none;
275
+ color: var(--second-color);
276
+ }
277
+
278
+ span[data-type="link-ref"],
279
+ sup[data-type="footnotes-ref"] {
280
+ color: @blurColor;
281
+ }
282
+
283
+ span[data-type="toc-h"] {
284
+ color: @blurColor;
285
+ text-decoration: underline;
286
+ }
287
+
288
+ div[data-type="footnotes-block"] {
289
+ border-top: 2px solid var(--heading-border-color);
290
+ padding-top: 24px;
291
+ margin-top: 24px;
292
+ }
293
+
294
+ div[data-type="link-ref-defs-block"] {
295
+ color: var(--blockquote-color);
296
+ }
297
+ }
298
+
299
+ @media screen and (max-width: @max-width) {
300
+ .vditor-wysiwyg {
301
+ h1:before,
302
+ h2:before,
303
+ h3:before,
304
+ h4:before,
305
+ h5:before,
306
+ h6:before,
307
+ div.vditor-wysiwyg__block:before,
308
+ div[data-type="link-ref-defs-block"]:before,
309
+ div[data-type="footnotes-block"]:before,
310
+ .vditor-toc:before {
311
+ content: none;
312
+ }
313
+ }
314
+ }
package/src/index.ts CHANGED
@@ -37,6 +37,7 @@ import {input} from "./ts/wysiwyg/input";
37
37
  import {renderDomByMd} from "./ts/wysiwyg/renderDomByMd";
38
38
  import {execAfterRender, insertEmptyBlock} from "./ts/util/fixBrowserBehavior";
39
39
  import {accessLocalStorage} from "./ts/util/compatibility";
40
+ import {initImageResize} from "./ts/util/imageResize";
40
41
 
41
42
  class Vditor extends VditorMethod {
42
43
  public readonly version: string;
@@ -552,6 +553,8 @@ class Vditor extends VditorMethod {
552
553
 
553
554
  initUI(this.vditor);
554
555
 
556
+ initImageResize(this.vditor);
557
+
555
558
  if (mergedOptions.after) {
556
559
  mergedOptions.after();
557
560
  }