@xaendar/common 0.5.3 → 0.5.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/dist/xaendar-common.es.d.ts +15 -0
- package/dist/xaendar-common.es.js +173 -1
- package/package.json +1 -1
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asserts that a given tag name is valid for use as a custom element name.
|
|
3
|
+
* A valid custom element name must:
|
|
4
|
+
* - contain a hyphen
|
|
5
|
+
* - no spaces.
|
|
6
|
+
* - start with a lowercase letter.
|
|
7
|
+
* - not contain uppercase letters.
|
|
8
|
+
* - not contain the following chars: '@', '#', '$', '%', '&', '*', '!', '?', '/', '\\', '|', "'", '"', '<', '>', '='
|
|
9
|
+
* - not be a native HTML tag name.
|
|
10
|
+
* - not be a reserved tag name.
|
|
11
|
+
* @param tagName The tag name to validate.
|
|
12
|
+
* @throws Will throw an error if the tag name is invalid.
|
|
13
|
+
*/
|
|
14
|
+
export declare function assertIsValidElementName(tagName: string): void;
|
|
15
|
+
|
|
1
16
|
/**
|
|
2
17
|
* Indents each line of a code block by two spaces.
|
|
3
18
|
* @param lines The lines of code to indent.
|
|
@@ -55,4 +55,176 @@ function indent(...lines) {
|
|
|
55
55
|
return lines.map((line) => ` ${line}`);
|
|
56
56
|
}
|
|
57
57
|
//#endregion
|
|
58
|
-
|
|
58
|
+
//#region ../packages/common/src/costants/base-tags.constants.ts
|
|
59
|
+
/**
|
|
60
|
+
* List of all standard, valid HTML tags in Xaendar Components's Template
|
|
61
|
+
*
|
|
62
|
+
* These are native HTML elements and should not be used as custom element names.
|
|
63
|
+
*/
|
|
64
|
+
var HTML_TAGS = [
|
|
65
|
+
"section",
|
|
66
|
+
"article",
|
|
67
|
+
"aside",
|
|
68
|
+
"nav",
|
|
69
|
+
"header",
|
|
70
|
+
"footer",
|
|
71
|
+
"address",
|
|
72
|
+
"h1",
|
|
73
|
+
"h2",
|
|
74
|
+
"h3",
|
|
75
|
+
"h4",
|
|
76
|
+
"h5",
|
|
77
|
+
"h6",
|
|
78
|
+
"p",
|
|
79
|
+
"hr",
|
|
80
|
+
"pre",
|
|
81
|
+
"blockquote",
|
|
82
|
+
"ol",
|
|
83
|
+
"ul",
|
|
84
|
+
"li",
|
|
85
|
+
"dl",
|
|
86
|
+
"dt",
|
|
87
|
+
"dd",
|
|
88
|
+
"figure",
|
|
89
|
+
"figcaption",
|
|
90
|
+
"div",
|
|
91
|
+
"a",
|
|
92
|
+
"span",
|
|
93
|
+
"br",
|
|
94
|
+
"wbr",
|
|
95
|
+
"b",
|
|
96
|
+
"strong",
|
|
97
|
+
"i",
|
|
98
|
+
"em",
|
|
99
|
+
"u",
|
|
100
|
+
"s",
|
|
101
|
+
"mark",
|
|
102
|
+
"small",
|
|
103
|
+
"sub",
|
|
104
|
+
"sup",
|
|
105
|
+
"abbr",
|
|
106
|
+
"cite",
|
|
107
|
+
"code",
|
|
108
|
+
"var",
|
|
109
|
+
"kbd",
|
|
110
|
+
"samp",
|
|
111
|
+
"time",
|
|
112
|
+
"data",
|
|
113
|
+
"dfn",
|
|
114
|
+
"q",
|
|
115
|
+
"ruby",
|
|
116
|
+
"rt",
|
|
117
|
+
"rp",
|
|
118
|
+
"bdi",
|
|
119
|
+
"bdo",
|
|
120
|
+
"ins",
|
|
121
|
+
"del",
|
|
122
|
+
"img",
|
|
123
|
+
"iframe",
|
|
124
|
+
"embed",
|
|
125
|
+
"object",
|
|
126
|
+
"param",
|
|
127
|
+
"picture",
|
|
128
|
+
"source",
|
|
129
|
+
"track",
|
|
130
|
+
"video",
|
|
131
|
+
"audio",
|
|
132
|
+
"map",
|
|
133
|
+
"area",
|
|
134
|
+
"table",
|
|
135
|
+
"caption",
|
|
136
|
+
"colgroup",
|
|
137
|
+
"col",
|
|
138
|
+
"tbody",
|
|
139
|
+
"thead",
|
|
140
|
+
"tfoot",
|
|
141
|
+
"tr",
|
|
142
|
+
"td",
|
|
143
|
+
"th",
|
|
144
|
+
"form",
|
|
145
|
+
"label",
|
|
146
|
+
"input",
|
|
147
|
+
"button",
|
|
148
|
+
"select",
|
|
149
|
+
"datalist",
|
|
150
|
+
"optgroup",
|
|
151
|
+
"option",
|
|
152
|
+
"textarea",
|
|
153
|
+
"output",
|
|
154
|
+
"progress",
|
|
155
|
+
"meter",
|
|
156
|
+
"fieldset",
|
|
157
|
+
"legend",
|
|
158
|
+
"details",
|
|
159
|
+
"summary",
|
|
160
|
+
"dialog",
|
|
161
|
+
"template",
|
|
162
|
+
"slot",
|
|
163
|
+
"canvas"
|
|
164
|
+
];
|
|
165
|
+
//#endregion
|
|
166
|
+
//#region ../packages/common/src/costants/not-alllowed-tags.constants.ts
|
|
167
|
+
/**
|
|
168
|
+
* List of strings not allowed as names for CustomElements
|
|
169
|
+
*/
|
|
170
|
+
var NOT_ALLOWED_TAGS = [
|
|
171
|
+
"annotation-xml",
|
|
172
|
+
"color-profile",
|
|
173
|
+
"font-face",
|
|
174
|
+
"font-face-src",
|
|
175
|
+
"font-face-uri",
|
|
176
|
+
"font-face-format",
|
|
177
|
+
"font-face-name",
|
|
178
|
+
"missing-glyph"
|
|
179
|
+
];
|
|
180
|
+
//#endregion
|
|
181
|
+
//#region ../packages/common/src/utils/tags/tags.utils.ts
|
|
182
|
+
/**
|
|
183
|
+
* Asserts that a given tag name is valid for use as a custom element name.
|
|
184
|
+
* A valid custom element name must:
|
|
185
|
+
* - contain a hyphen
|
|
186
|
+
* - no spaces.
|
|
187
|
+
* - start with a lowercase letter.
|
|
188
|
+
* - not contain uppercase letters.
|
|
189
|
+
* - not contain the following chars: '@', '#', '$', '%', '&', '*', '!', '?', '/', '\\', '|', "'", '"', '<', '>', '='
|
|
190
|
+
* - not be a native HTML tag name.
|
|
191
|
+
* - not be a reserved tag name.
|
|
192
|
+
* @param tagName The tag name to validate.
|
|
193
|
+
* @throws Will throw an error if the tag name is invalid.
|
|
194
|
+
*/
|
|
195
|
+
function assertIsValidElementName(tagName) {
|
|
196
|
+
if (!/^[a-z][a-z0-9._\-]*-[a-z0-9._\-]*$/.test(tagName)) throw new Error(`Tag <${tagName}> is not a valid custom element name. Custom element names must:
|
|
197
|
+
- contain a hyphen
|
|
198
|
+
- no spaces.
|
|
199
|
+
- start with a lowercase letter.
|
|
200
|
+
- not contain uppercase letters.
|
|
201
|
+
- not contain the following chars: '@', '#', '$', '%', '&', '*', '!', '?', '/', '\\', '|', "'", '"', '<', '>', '='
|
|
202
|
+
`);
|
|
203
|
+
if (isNativeHTMLTag(tagName)) throw new Error(`Tag <${tagName}> is a native HTML tag and cannot be used as a custom element name.`);
|
|
204
|
+
if (isReservedTagName(tagName)) throw new Error(`Tag <${tagName}> is a reserved tag name and cannot be used as a custom element name.
|
|
205
|
+
Reserved names are:
|
|
206
|
+
- ${NOT_ALLOWED_TAGS.join("\n- ")}`);
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Checks if a tag name is a native HTML tag.
|
|
210
|
+
*
|
|
211
|
+
* @param tagName - The tag name to check.
|
|
212
|
+
* @returns `true` if the tag name is a standard HTML tag, `false` otherwise.
|
|
213
|
+
*/
|
|
214
|
+
function isNativeHTMLTag(tagName) {
|
|
215
|
+
return HTML_TAGS.includes(tagName);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Checks if a tag name is reserved and cannot be used for a custom element.
|
|
219
|
+
*
|
|
220
|
+
* Reserved names include certain HTML, SVG, or other names that are forbidden by the specification.
|
|
221
|
+
* https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
|
|
222
|
+
*
|
|
223
|
+
* @param tagName - The tag name to check.
|
|
224
|
+
* @returns `true` if the tag name is reserved, `false` otherwise.
|
|
225
|
+
*/
|
|
226
|
+
function isReservedTagName(tagName) {
|
|
227
|
+
return NOT_ALLOWED_TAGS.includes(tagName);
|
|
228
|
+
}
|
|
229
|
+
//#endregion
|
|
230
|
+
export { Stack, assertIsValidElementName, indent };
|