@wc-toolkit/cem-generator-svelte 0.1.6 → 0.1.8

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 (2) hide show
  1. package/dist/index.js +62 -17
  2. package/package.json +15 -15
package/dist/index.js CHANGED
@@ -21,14 +21,18 @@ export function sveltePlugin() {
21
21
  summary: metadata.summary,
22
22
  deprecated: metadata.deprecated,
23
23
  tagName: metadata.tagName ?? tagName,
24
- members: props.length ? props.map(({ attribute: _attribute, ...member }) => member) : undefined,
25
- attributes: props.length ? props.map(({ name: fieldName, type, parsedType, description, attribute }) => ({
26
- name: attribute ?? fieldName,
27
- type,
28
- parsedType,
29
- description,
30
- fieldName,
31
- })) : undefined,
24
+ members: props.length
25
+ ? props.map(({ attribute: _attribute, ...member }) => member)
26
+ : undefined,
27
+ attributes: props.length
28
+ ? props.map(({ name: fieldName, type, parsedType, description, attribute }) => ({
29
+ name: attribute ?? fieldName,
30
+ type,
31
+ parsedType,
32
+ description,
33
+ fieldName,
34
+ }))
35
+ : undefined,
32
36
  events: mergeNamed(discoverEvents(source), metadata.events),
33
37
  slots: mergeNamed(discoverSlots(source), metadata.slots),
34
38
  cssParts: mergeNamed(discoverParts(source), metadata.cssParts),
@@ -44,7 +48,9 @@ function getTagName(source) {
44
48
  return options?.[1] ?? options?.[2];
45
49
  }
46
50
  function getComponentName(filePath) {
47
- return path.basename(filePath, ".svelte").replace(/[^A-Za-z0-9]+(.)/g, (_match, character) => character.toUpperCase());
51
+ return path
52
+ .basename(filePath, ".svelte")
53
+ .replace(/[^A-Za-z0-9]+(.)/g, (_match, character) => character.toUpperCase());
48
54
  }
49
55
  function getProps(source) {
50
56
  const props = [];
@@ -55,7 +61,14 @@ function getProps(source) {
55
61
  }
56
62
  for (const match of script.matchAll(/(?:\/\*\*([\s\S]*?)\*\/\s*)?export\s+let\s+(\w+)\s*(?::\s*([^=;]+))?\s*(?:=\s*([^;\n]+))?/g)) {
57
63
  const [, comment, name, type, defaultValue] = match;
58
- props.push({ name, kind: "field", type: type?.trim() ?? inferType(defaultValue), description: cleanComment(comment), default: defaultValue?.trim(), attribute: name.toLowerCase() });
64
+ props.push({
65
+ name,
66
+ kind: "field",
67
+ type: type?.trim() ?? inferType(defaultValue),
68
+ description: cleanComment(comment),
69
+ default: defaultValue?.trim(),
70
+ attribute: name.toLowerCase(),
71
+ });
59
72
  }
60
73
  const runeProps = script.match(/\b(?:let|const)\s*\{([\s\S]*?)\}\s*(?::\s*(\w+))?\s*=\s*\$props\s*\(\s*\)/)?.[1];
61
74
  for (const entry of runeProps?.split(",") ?? []) {
@@ -63,7 +76,14 @@ function getProps(source) {
63
76
  if (!match || props.some((prop) => prop.name === match[1]))
64
77
  continue;
65
78
  const info = interfaces.get(match[1]);
66
- props.push({ name: match[1], kind: "field", type: info?.type ?? inferType(match[2]), description: info?.description, default: match[2]?.trim(), attribute: match[1].toLowerCase() });
79
+ props.push({
80
+ name: match[1],
81
+ kind: "field",
82
+ type: info?.type ?? inferType(match[2]),
83
+ description: info?.description,
84
+ default: match[2]?.trim(),
85
+ attribute: match[1].toLowerCase(),
86
+ });
67
87
  }
68
88
  const options = source.match(/<svelte:options\b([\s\S]*?)\/>/)?.[1] ?? "";
69
89
  for (const match of options.matchAll(/(\w+)\s*:\s*\{[^}]*?attribute\s*:\s*["']([^"']+)["'][^}]*\}/g)) {
@@ -91,10 +111,19 @@ function getComponentMetadata(source, tagName) {
91
111
  };
92
112
  }
93
113
  function discoverSlots(source) {
94
- return [...source.matchAll(/<slot(?:\s+name\s*=\s*["']([^"']+)["'])?[^>]*>/g)].map((match) => ({ name: match[1] ?? "", description: trailingHtmlComment(source.slice(0, match.index ?? 0)) }));
114
+ return [...source.matchAll(/<slot(?:\s+name\s*=\s*["']([^"']+)["'])?[^>]*>/g)].map((match) => ({
115
+ name: match[1] ?? "",
116
+ description: trailingHtmlComment(source.slice(0, match.index ?? 0)),
117
+ }));
95
118
  }
96
119
  function discoverParts(source) {
97
- return [...source.matchAll(/<[^>]*\bpart\s*=\s*["']([^"']+)["'][^>]*>/g)].flatMap((match) => match[1].split(/\s+/).filter(Boolean).map((name) => ({ name, description: trailingHtmlComment(source.slice(0, match.index ?? 0)) })));
120
+ return [...source.matchAll(/<[^>]*\bpart\s*=\s*["']([^"']+)["'][^>]*>/g)].flatMap((match) => match[1]
121
+ .split(/\s+/)
122
+ .filter(Boolean)
123
+ .map((name) => ({
124
+ name,
125
+ description: trailingHtmlComment(source.slice(0, match.index ?? 0)),
126
+ })));
98
127
  }
99
128
  function discoverCssProperties(source) {
100
129
  const properties = [];
@@ -109,11 +138,22 @@ function discoverEvents(source) {
109
138
  return events;
110
139
  }
111
140
  function parseNamedTags(comment, tag) {
112
- const values = [...comment.matchAll(new RegExp(`@${tag}\\s+([^\\s-]+|-)\\s*(?:-\\s*)?([^\\n]*)`, "g"))].map((match) => ({ name: match[1] === "-" ? "" : match[1], description: match[2]?.trim() || undefined }));
141
+ const values = [
142
+ ...comment.matchAll(new RegExp(`@${tag}\\s+([^\\s-]+|-)\\s*(?:-\\s*)?([^\\n]*)`, "g")),
143
+ ].map((match) => ({
144
+ name: match[1] === "-" ? "" : match[1],
145
+ description: match[2]?.trim() || undefined,
146
+ }));
113
147
  return values.length ? values : undefined;
114
148
  }
115
149
  function parseCssTags(comment) {
116
- const values = [...comment.matchAll(/@cssprop(?:erty)?\s+(?:\[([^=\]]+)=([^\]]+)\]|(\S+))\s*(?:-\s*)?([^\n]*)/g)].map((match) => ({ name: match[1] ?? match[3], default: match[2], description: match[4]?.trim() || undefined }));
150
+ const values = [
151
+ ...comment.matchAll(/@cssprop(?:erty)?\s+(?:\[([^=\]]+)=([^\]]+)\]|(\S+))\s*(?:-\s*)?([^\n]*)/g),
152
+ ].map((match) => ({
153
+ name: match[1] ?? match[3],
154
+ default: match[2],
155
+ description: match[4]?.trim() || undefined,
156
+ }));
117
157
  return values.length ? values : undefined;
118
158
  }
119
159
  function getTagDescription(comment, tag) {
@@ -122,7 +162,12 @@ function getTagDescription(comment, tag) {
122
162
  function cleanComment(value) {
123
163
  if (!value)
124
164
  return undefined;
125
- const text = value.split("\n").map((line) => line.replace(/^\s*\*\s?/, "")).join(" ").replace(/\s+/g, " ").trim();
165
+ const text = value
166
+ .split("\n")
167
+ .map((line) => line.replace(/^\s*\*\s?/, ""))
168
+ .join(" ")
169
+ .replace(/\s+/g, " ")
170
+ .trim();
126
171
  return text || undefined;
127
172
  }
128
173
  function trailingHtmlComment(value) {
@@ -141,7 +186,7 @@ function inferType(value) {
141
186
  return "boolean";
142
187
  if (/^\d/.test(value))
143
188
  return "number";
144
- if (/^[\[{]/.test(value))
189
+ if (/^[[{]/.test(value))
145
190
  return value.startsWith("[") ? "array" : "object";
146
191
  return undefined;
147
192
  }
package/package.json CHANGED
@@ -1,37 +1,37 @@
1
1
  {
2
2
  "name": "@wc-toolkit/cem-generator-svelte",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "Svelte detector plugin for generating Custom Elements Manifests.",
5
+ "keywords": [
6
+ "custom-elements",
7
+ "custom-elements-manifest",
8
+ "svelte",
9
+ "web-components"
10
+ ],
11
+ "homepage": "https://cem-generator.wc-toolkit.com/plugins/svelte/",
12
+ "bugs": {
13
+ "url": "https://github.com/wc-toolkit/cem-generator/issues"
14
+ },
5
15
  "license": "MIT",
6
16
  "repository": {
7
17
  "type": "git",
8
18
  "url": "git+https://github.com/wc-toolkit/cem-generator.git",
9
19
  "directory": "packages/plugins/svelte"
10
20
  },
11
- "bugs": {
12
- "url": "https://github.com/wc-toolkit/cem-generator/issues"
13
- },
14
- "homepage": "https://wc-toolkit.github.io/cem-generator/plugins/svelte/",
15
- "keywords": [
16
- "custom-elements",
17
- "custom-elements-manifest",
18
- "web-components",
19
- "svelte"
21
+ "files": [
22
+ "dist"
20
23
  ],
21
24
  "type": "module",
22
25
  "main": "./dist/index.js",
23
26
  "types": "./dist/index.d.ts",
24
- "files": [
25
- "dist"
26
- ],
27
27
  "publishConfig": {
28
28
  "access": "public",
29
29
  "provenance": true
30
30
  },
31
31
  "dependencies": {
32
32
  "typescript": "^5.9.0",
33
- "@wc-toolkit/cem-generator": "0.1.6",
34
- "@wc-toolkit/cem-generator-utils": "0.1.1"
33
+ "@wc-toolkit/cem-generator": "0.1.8",
34
+ "@wc-toolkit/cem-generator-utils": "0.1.2"
35
35
  },
36
36
  "devDependencies": {
37
37
  "svelte": "^5.0.0"