@valten/regulex-visualizer 1.0.1 → 1.0.4

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valten/regulex-visualizer",
3
- "version": "1.0.1",
3
+ "version": "1.0.4",
4
4
  "description": "A Vue component for visualizing regular expressions",
5
5
  "keywords": [
6
6
  "vue",
@@ -13,7 +13,7 @@
13
13
  "type": "module",
14
14
  "main": "dist/index.js",
15
15
  "module": "dist/index.js",
16
- "types": "dist/index.d.ts",
16
+ "types": "dist/index.js",
17
17
  "files": [
18
18
  "dist",
19
19
  "src"
@@ -31,7 +31,6 @@
31
31
  "devDependencies": {
32
32
  "@types/node": "^20.0.0",
33
33
  "@vitejs/plugin-vue": "^5.2.1",
34
- "typescript": "^5.4.2",
35
34
  "vite": "^6.0.11",
36
35
  "vue": "^3.0.0"
37
36
  }
@@ -43,22 +43,28 @@
43
43
  </div>
44
44
  </template>
45
45
 
46
- <script setup lang="ts">
46
+ <script setup>
47
47
  import { ref, computed, onMounted, nextTick, watch } from 'vue';
48
48
  import regulexScript from '../assets/regulex.js?url';
49
49
 
50
- const props = defineProps<{ pattern: string }>();
50
+ const props = defineProps({
51
+ pattern: {
52
+ type: String,
53
+ default: ''
54
+ }
55
+ });
56
+
51
57
  const emit = defineEmits(['update:pattern']);
52
58
 
53
59
  // 响应式数据
54
- const regexInput = ref(props.pattern || '^(a|b)*?$');
60
+ const regexInput = ref(props.pattern || '^1[3-9]\\d{9}$');
55
61
  const flagI = ref(false);
56
62
  const flagM = ref(false);
57
63
  const flagG = ref(false);
58
64
  const errorMessage = ref('');
59
- const graphContainer = ref<HTMLElement | null>(null);
60
- const paper = ref<any>(null);
61
- const regulexDeps = ref<any>(null);
65
+ const graphContainer = ref(null);
66
+ const paper = ref(null);
67
+ const regulexDeps = ref(null);
62
68
  const params = ref({
63
69
  embed: false,
64
70
  re: '',
@@ -81,18 +87,19 @@ watch(regexInput, (val) => {
81
87
  emit('update:pattern', `/${val}/${flags.value}`);
82
88
  visualize();
83
89
  });
90
+
84
91
  // 父组件 pattern 变化时同步到输入框
85
92
  watch(() => props.pattern, (val) => {
86
93
  if (val !== regexInput.value) parseFullRegexString(val);
87
94
  });
88
95
 
89
96
  // 工具函数
90
- function trim(s: string) {
97
+ function trim(s) {
91
98
  return s.replace(/^\s+/, '').replace(/\s+$/, '');
92
99
  }
93
100
 
94
101
  // 辅助函数:从完整的正则表达式字符串(如 /regex/flags)中解析标志并更新状态
95
- function parseFullRegexString(fullString: string) {
102
+ function parseFullRegexString(fullString) {
96
103
  const match = fullString.match(/^\/(.*)\/([gimsuy]*)$/);
97
104
  if (match) {
98
105
  regexInput.value = match[1];
@@ -116,7 +123,7 @@ function getParams() {
116
123
  }
117
124
 
118
125
  const paramsStr = hash.slice(2);
119
- const paramsObj = paramsStr.split("&").reduce((p: any, a) => {
126
+ const paramsObj = paramsStr.split("&").reduce((p, a) => {
120
127
  const parts = a.split("=");
121
128
  p[parts[0]] = parts[1];
122
129
  return p;
@@ -148,7 +155,7 @@ function hideError() {
148
155
  errorMessage.value = '';
149
156
  }
150
157
 
151
- function showError(re: string, err: any) {
158
+ function showError(re, err) {
152
159
  let msg = ["Error:" + err.message, ""];
153
160
  if (typeof err.lastIndex === 'number') {
154
161
  msg.push(re);
@@ -161,9 +168,9 @@ function showError(re: string, err: any) {
161
168
  function getRegulexDependencies() {
162
169
  try {
163
170
  if (typeof window !== 'undefined') {
164
- if ((window as any).require) {
171
+ if (window.require) {
165
172
  try {
166
- const regulex = (window as any).require('regulex');
173
+ const regulex = window.require('regulex');
167
174
  if (regulex) {
168
175
  return {
169
176
  parse: regulex.parse,
@@ -185,9 +192,9 @@ function getRegulexDependencies() {
185
192
  }
186
193
 
187
194
  // 动态加载 regulex 脚本
188
- function loadRegulexScript(): Promise<any> {
195
+ function loadRegulexScript() {
189
196
  return new Promise((resolve, reject) => {
190
- if ((window as any).regulexLoaded) {
197
+ if (window.regulexLoaded) {
191
198
  const deps = getRegulexDependencies();
192
199
  if (deps) {
193
200
  resolve(deps);
@@ -202,7 +209,7 @@ function loadRegulexScript(): Promise<any> {
202
209
  script.src = regulexScript;
203
210
 
204
211
  script.onload = () => {
205
- (window as any).regulexLoaded = true;
212
+ window.regulexLoaded = true;
206
213
  const deps = getRegulexDependencies();
207
214
  if (deps) {
208
215
  resolve(deps);
@@ -247,7 +254,7 @@ function visualize(skipError = false) {
247
254
  // 可视化
248
255
  regulexDeps.value.visualize(ast, flags.value, paper.value);
249
256
  return true;
250
- } catch (e: any) {
257
+ } catch (e) {
251
258
  if (!skipError) {
252
259
  showError(re, e);
253
260
  }
@@ -261,15 +268,15 @@ function onFlagChange() {
261
268
  changeHash();
262
269
  }
263
270
 
264
- function onKeyup(e: KeyboardEvent) {
271
+ function onKeyup(e) {
265
272
  if (e.keyCode === 13) return; // Enter
266
- clearTimeout((window as any).onKeyupTid);
267
- (window as any).onKeyupTid = setTimeout(() => {
273
+ clearTimeout(window.onKeyupTid);
274
+ window.onKeyupTid = setTimeout(() => {
268
275
  visualize();
269
276
  }, 100);
270
277
  }
271
278
 
272
- function onEnter(e: KeyboardEvent) {
279
+ function onEnter(e) {
273
280
  if (e.keyCode === 13) {
274
281
  e.preventDefault();
275
282
  e.stopPropagation();
@@ -278,12 +285,12 @@ function onEnter(e: KeyboardEvent) {
278
285
  }
279
286
 
280
287
  // 拖拽功能
281
- function dragGraph(container: HTMLElement) {
288
+ function dragGraph(container) {
282
289
  if (!container) return;
283
290
 
284
291
  container.addEventListener('mousedown', startMove);
285
292
 
286
- function startMove(e: MouseEvent) {
293
+ function startMove(e) {
287
294
  clearSelect();
288
295
  let x = e.clientX, y = e.clientY;
289
296
  container.addEventListener('mousemove', onMove);
@@ -291,13 +298,13 @@ function dragGraph(container: HTMLElement) {
291
298
  document.addEventListener('mouseup', unbind, true);
292
299
  window.addEventListener('mouseup', unbind, true);
293
300
 
294
- function unbind(e: Event) {
301
+ function unbind(e) {
295
302
  container.removeEventListener('mousemove', onMove);
296
303
  document.removeEventListener('mouseup', unbind, true);
297
304
  window.removeEventListener('mouseup', unbind, true);
298
305
  }
299
306
 
300
- function onMove(e: MouseEvent) {
307
+ function onMove(e) {
301
308
  let dx = x - e.clientX, dy = y - e.clientY;
302
309
  if (dx > 0 && container.scrollWidth - container.scrollLeft - container.clientWidth < 2
303
310
  || dx < 0 && container.scrollLeft < 1) {
@@ -321,13 +328,13 @@ function dragGraph(container: HTMLElement) {
321
328
 
322
329
  function clearSelect() {
323
330
  if (window.getSelection) {
324
- if ((window.getSelection() as any).empty) {
325
- (window.getSelection() as any).empty();
331
+ if (window.getSelection().empty) {
332
+ window.getSelection().empty();
326
333
  } else if (window.getSelection()?.removeAllRanges) {
327
334
  window.getSelection()?.removeAllRanges();
328
335
  }
329
- } else if ((document as any).selection) {
330
- (document as any).selection.empty();
336
+ } else if (document.selection) {
337
+ document.selection.empty();
331
338
  }
332
339
  }
333
340
 
package/src/env.d.ts DELETED
@@ -1,5 +0,0 @@
1
- // src/env.d.ts
2
- declare module '*.js?url' {
3
- const src: string;
4
- export default src;
5
- }
package/src/index.d.ts DELETED
@@ -1,13 +0,0 @@
1
- // index.d.ts
2
- import { DefineComponent, App } from 'vue';
3
-
4
- // 1. 定义组件的类型
5
- // 如果你的组件有 Props,可以将 {} 替换为具体的接口
6
- declare const RegulexVisualizer: DefineComponent<{}, {}, any>;
7
-
8
- // 2. 导出具名组件
9
- export { RegulexVisualizer };
10
-
11
- // 3. (可选) 如果你支持 Vue.use() 全局安装,导出插件类型
12
- declare const install: (app: App) => void;
13
- export default install;
File without changes