renusify 1.2.3 → 1.2.5

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,242 @@
1
+ <template>
2
+ <div class="code-editor-highlight ltr">
3
+ <textarea
4
+ v-model="d"
5
+ autocapitalize="off"
6
+ autocomplete="off"
7
+ autocorrect="off"
8
+ spellcheck="false"
9
+ ></textarea>
10
+ <div class="text-preview" v-html="build"></div>
11
+ </div>
12
+ </template>
13
+
14
+ <script>
15
+ export default {
16
+ name: "highlight-script",
17
+ props: {
18
+ modelValue: String,
19
+ },
20
+ data() {
21
+ return {
22
+ d: this.modelValue,
23
+ runnable: false,
24
+ code: "",
25
+ };
26
+ },
27
+ watch: {
28
+ modelValue: function () {
29
+ this.d = this.modelValue;
30
+ },
31
+ d: function () {
32
+ this.$emit("update:model-value", this.d);
33
+ },
34
+ },
35
+ computed: {
36
+ build() {
37
+ if (!this.d) {
38
+ return "";
39
+ }
40
+ let data = this.d.split("");
41
+ let str = this.d.trim();
42
+
43
+ if (str.substr(0, 1) === "{") {
44
+ str = str.substr(1, str.length - 2);
45
+ }
46
+ let res = "";
47
+
48
+ let in_quta = false;
49
+ data.forEach((c) => {
50
+ if (["=", "&", "{", "}", "<", ">"].includes(c)) {
51
+ res += '<span class="color-blue code-editor-span">' + c + "</span>";
52
+ } else if ([",", ";", ":"].includes(c)) {
53
+ res += '<span class="color-orange code-editor-span">' + c + "</span>";
54
+ } else if (parseInt(c) > -1) {
55
+ res += '<span class="color-number code-editor-span">' + c + "</span>";
56
+ } else if ((c === '"' || c === "'" || c === "`") && !in_quta) {
57
+ in_quta = c;
58
+ res += '<span class="color-green code-editor-span">' + c;
59
+ } else if (c === in_quta) {
60
+ in_quta = false;
61
+ res += c + "</span>";
62
+ } else {
63
+ res += c;
64
+ }
65
+ });
66
+
67
+ res = this.re_words(res);
68
+ res = this.re_comment(res);
69
+ res = this.re_func(res);
70
+
71
+ // main function vuejs methods created ,...
72
+ this.strToObj(str).forEach((item) => {
73
+ if (item) {
74
+ res = this.$helper.replacer(
75
+ res,
76
+ item,
77
+ '<span class="color-func code-editor-span">' + item + "</span>"
78
+ );
79
+ }
80
+ });
81
+
82
+ return res;
83
+ },
84
+ },
85
+ methods: {
86
+ strToObj(str) {
87
+ str = this.$helper.replacer(str, " ", "");
88
+ str = this.$helper.replacer(str, "\n", "");
89
+ str = this.$helper.replacer(str, "\r", "");
90
+ let open = 0;
91
+ let pre = 0;
92
+ let to = 0;
93
+ let items = [];
94
+ const s = str;
95
+ s.split("").forEach((c, i) => {
96
+ to++;
97
+ if (c === "{") {
98
+ open++;
99
+ }
100
+ if (c === "}") {
101
+ open--;
102
+ }
103
+ if (open === 0 && c === ",") {
104
+ let new_str = str.substr(pre, to - 1);
105
+ const o = new_str.indexOf(":");
106
+ const f = new_str.indexOf("(");
107
+ if ((f > 0 && f < o) || o < 0) {
108
+ new_str = new_str.substr(0, f);
109
+ } else {
110
+ new_str = new_str.substr(0, o);
111
+ }
112
+ items.push(new_str);
113
+ pre = i + 1;
114
+ to = 0;
115
+ }
116
+ });
117
+ let new_str = str.substr(pre, str.length);
118
+ const o = new_str.indexOf(":");
119
+ const f = new_str.indexOf("(");
120
+ if ((f > 0 && f < o) || o < 0) {
121
+ new_str = new_str.substr(0, f);
122
+ } else {
123
+ new_str = new_str.substr(0, o);
124
+ }
125
+ items.push(new_str);
126
+ return items;
127
+ },
128
+ re_words(res) {
129
+ res = this.$helper.replacer(
130
+ res,
131
+ "import ",
132
+ '<span class="color-orange code-editor-span">import</span> '
133
+ );
134
+ res = this.$helper.replacer(
135
+ res,
136
+ " from ",
137
+ ' <span class="color-orange code-editor-span">from</span> '
138
+ );
139
+ res = this.$helper.replacer(
140
+ res,
141
+ " window.",
142
+ ' <span class="color-orange code-editor-span">window</span>.'
143
+ );
144
+ res = this.$helper.replacer(
145
+ res,
146
+ " new ",
147
+ ' <span class="color-orange code-editor-span">new</span> '
148
+ );
149
+ res = this.$helper.replacer(
150
+ res,
151
+ " var ",
152
+ ' <span class="color-orange code-editor-span">var</span> '
153
+ );
154
+ res = this.$helper.replacer(
155
+ res,
156
+ " let ",
157
+ ' <span class="color-orange code-editor-span">let</span> '
158
+ );
159
+ res = this.$helper.replacer(
160
+ res,
161
+ " const ",
162
+ ' <span class="color-orange code-editor-span">const</span> '
163
+ );
164
+ res = this.$helper.replacer(
165
+ res,
166
+ " return ",
167
+ ' <span class="color-orange code-editor-span">return</span> '
168
+ );
169
+ res = this.$helper.replacer(
170
+ res,
171
+ " true",
172
+ ' <span class="color-orange code-editor-span">true</span>'
173
+ );
174
+ res = this.$helper.replacer(
175
+ res,
176
+ " false",
177
+ ' <span class="color-orange code-editor-span">false</span>'
178
+ );
179
+ res = this.$helper.replacer(
180
+ res,
181
+ " this.",
182
+ ' <span class="color-orange code-editor-span">this</span>.'
183
+ );
184
+
185
+ return res;
186
+ },
187
+ re_comment(res) {
188
+ //eslint-disable-next-line
189
+ let regex = /(\/\*[\w\'\s\r\n\*]*\*\/)|(\/\/[\w\s\']*)/g;
190
+ let matched = res.matchAll(regex);
191
+ for (const match of matched) {
192
+ res = this.$helper.replacer(
193
+ res,
194
+ match[0],
195
+ '<span class="color-comment code-editor-span">' + match[0] + "</span>"
196
+ );
197
+ }
198
+ return res;
199
+ },
200
+ re_func(res) {
201
+ //function like Date()
202
+ let regex = /([a-zA-Z_{1}][a-zA-Z0-9_]+)[ ]{0,1}(?=\()/g;
203
+ let matched = res.matchAll(regex);
204
+ for (const match of matched) {
205
+ res = this.$helper.replacer(
206
+ res,
207
+ match[0],
208
+ '<span class="color-func2 code-editor-span">' + match[0] + "</span>"
209
+ );
210
+ }
211
+
212
+ //function like $r $d()
213
+ regex = /(\$([a-zA-z0-9]*)[.|(])/g;
214
+ matched = res.matchAll(regex);
215
+ for (const match of matched) {
216
+ res = this.$helper.replacer(
217
+ res,
218
+ match[0].substr(0, match[0].length - 1),
219
+ '<span class="color-func code-editor-span">' +
220
+ match[0].substr(0, match[0].length - 1) +
221
+ "</span>"
222
+ );
223
+ }
224
+ res = this.$helper.replacer(
225
+ res,
226
+ "(",
227
+ '<span class="color-func2 code-editor-span">(</span>'
228
+ );
229
+ res = this.$helper.replacer(
230
+ res,
231
+ ")",
232
+ '<span class="color-func2 code-editor-span">)</span>'
233
+ );
234
+ return res;
235
+ },
236
+ },
237
+ };
238
+ </script>
239
+
240
+ <style lang="scss">
241
+ @import "~renusify/style/include";
242
+ </style>