@typlog/ui 0.10.0 → 0.11.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.
Files changed (36) hide show
  1. package/dist/addons.css +113 -0
  2. package/dist/addons.d.ts +48 -0
  3. package/dist/addons.js +442 -0
  4. package/dist/components/accordion.css +149 -0
  5. package/dist/components/avatar.css +131 -0
  6. package/dist/components/badge.css +75 -0
  7. package/dist/{base.css → components/base.css} +726 -832
  8. package/dist/components/button.css +317 -0
  9. package/dist/components/card.css +86 -0
  10. package/dist/components/checkbox.css +90 -0
  11. package/dist/components/collapsible.css +27 -0
  12. package/dist/components/combobox.css +388 -0
  13. package/dist/components/dialog.css +488 -0
  14. package/dist/components/dropdown.css +204 -0
  15. package/dist/components/editable.css +34 -0
  16. package/dist/components/icon.css +109 -0
  17. package/dist/components/inputs.css +570 -0
  18. package/dist/components/inset.css +73 -0
  19. package/dist/components/pagination.css +299 -0
  20. package/dist/components/popover.css +69 -0
  21. package/dist/components/quota.css +14 -0
  22. package/dist/components/radio.css +211 -0
  23. package/dist/components/scrollarea.css +107 -0
  24. package/dist/components/select.css +308 -0
  25. package/dist/components/separator.css +26 -0
  26. package/dist/components/spinner.css +36 -0
  27. package/dist/components/switch.css +176 -0
  28. package/dist/components/table.css +198 -0
  29. package/dist/components/tabs.css +122 -0
  30. package/dist/components/toggle.css +188 -0
  31. package/dist/components/tooltip.css +37 -0
  32. package/dist/components.css +3548 -0
  33. package/dist/{index.d.ts → components.d.ts} +131 -107
  34. package/dist/{index.js → components.js} +323 -681
  35. package/package.json +28 -14
  36. package/dist/style.css +0 -10463
@@ -0,0 +1,113 @@
1
+
2
+ .ui-IconifySample {
3
+ display: flex;
4
+ gap: var(--space-4);
5
+ padding: var(--space-2);
6
+ justify-content: space-between;
7
+ align-items: center;
8
+ text-align: left;
9
+ border-radius: var(--radius-3);
10
+ background: var(--gray-a2);
11
+ }
12
+ .ui-IconifySample:hover {
13
+ background: var(--gray-a3);
14
+ }
15
+ .ui-IconifySampleInfo {
16
+ display: flex;
17
+ flex-direction: column;
18
+ gap: var(--space-1);
19
+ }
20
+ .ui-IconifySampleInfo > strong {
21
+ font-weight: var(--font-weight-medium);
22
+ font-size: var(--font-size-2);
23
+ line-height: var(--line-height-2);
24
+ }
25
+ .ui-IconifySampleInfo > span {
26
+ font-weight: var(--font-weight-regular);
27
+ font-size: var(--font-size-1);
28
+ line-height: var(--line-height-1);
29
+ color: var(--gray-a10);
30
+ }
31
+ .ui-IconifySampleIcons {
32
+ display: grid;
33
+ grid-template-columns: repeat(3, minmax(0, 1fr));
34
+ gap: var(--space-2);
35
+ }
36
+
37
+ .ui-IconifyCollection {
38
+ container-name: icon-collection;
39
+ container-type: inline-size;
40
+ }
41
+ .ui-IconifyCollectionForm {
42
+ display: flex;
43
+ flex-grow: 1;
44
+ align-items: center;
45
+ gap: var(--space-4);
46
+ }
47
+ .ui-IconifyCollectionForm .ui-TextField {
48
+ flex-grow: 1;
49
+ }
50
+ .ui-IconifyCollectionGroupsHead {
51
+ display: flex;
52
+ flex-direction: column;
53
+ align-items: center;
54
+ gap: var(--space-8);
55
+ margin-bottom: var(--space-4);
56
+ }
57
+ @container icon-collection (min-width: 768px) {
58
+ .ui-IconifyCollectionGroupsHead {
59
+ flex-direction: row;
60
+ }
61
+ }
62
+ .ui-IconifyCollectionGroupsHead > h1 {
63
+ font-weight: var(--font-weight-medium);
64
+ font-size: var(--font-size-4);
65
+ line-height: var(--line-height-4);
66
+ }
67
+ .ui-IconifyCollectionSample {
68
+ margin-bottom: var(--space-4);
69
+ }
70
+ .ui-IconifyCollectionSampleGrid {
71
+ margin-top: var(--space-2);
72
+ display: grid;
73
+ gap: var(--space-2);
74
+ grid-template-columns: repeat(1, minmax(0, 1fr));
75
+ }
76
+ @container icon-collection (min-width: 768px) {
77
+ .ui-IconifyCollectionSampleGrid {
78
+ grid-template-columns: repeat(2, minmax(0, 1fr));
79
+ }
80
+ }
81
+ @container icon-collection (min-width: 1024px) {
82
+ .ui-IconifyCollectionSampleGrid {
83
+ grid-template-columns: repeat(3, minmax(0, 1fr));
84
+ }
85
+ }
86
+ @container icon-collection (min-width: 1280px) {
87
+ .ui-IconifyCollectionSampleGrid {
88
+ grid-template-columns: repeat(4, minmax(0, 1fr));
89
+ }
90
+ }
91
+ .ui-IconifyCollectionSuffixes {
92
+ display: flex;
93
+ flex-wrap: wrap;
94
+ gap: var(--space-2);
95
+ flex-grow: 1;
96
+ margin-top: var(--space-4);
97
+ }
98
+ .ui-IconifyCollectionIconGrid {
99
+ display: flex;
100
+ flex-wrap: wrap;
101
+ gap: var(--space-3);
102
+ flex-grow: 1;
103
+ margin-top: var(--space-4);
104
+ margin-bottom: var(--space-4);
105
+ }
106
+ .ui-IconifyCollectionIconGrid button {
107
+ border: 0;
108
+ padding: var(--space-2);
109
+ border-radius: max(var(--radius-2), var(--radius-full));
110
+ }
111
+ .ui-IconifyCollectionIconGrid button:hover {
112
+ background-color: var(--gray-a4);
113
+ }
@@ -0,0 +1,48 @@
1
+ import { ComponentOptionsMixin } from 'vue';
2
+ import { ComponentProvideOptions } from 'vue';
3
+ import { DefineComponent } from 'vue';
4
+ import { PublicProps } from 'vue';
5
+
6
+ export declare const IconifyCollection: DefineComponent<IconifyCollectionProps, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {
7
+ select: (icon: string) => any;
8
+ }, string, PublicProps, Readonly<IconifyCollectionProps> & Readonly<{
9
+ onSelect?: ((icon: string) => any) | undefined;
10
+ }>, {
11
+ perpage: number;
12
+ iconSize: string | number;
13
+ }, {}, {}, {}, string, ComponentProvideOptions, false, {}, HTMLDivElement>;
14
+
15
+ declare interface IconifyCollectionProps {
16
+ prefix?: string;
17
+ search?: string;
18
+ perpage?: number;
19
+ iconSize?: string | number;
20
+ }
21
+
22
+ export declare const Turnstile: DefineComponent<TurnstileProps, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {
23
+ "update:modelValue": (args_0: string) => any;
24
+ }, string, PublicProps, Readonly<TurnstileProps> & Readonly<{
25
+ "onUpdate:modelValue"?: ((args_0: string) => any) | undefined;
26
+ }>, {
27
+ size: "normal" | "compact";
28
+ resetInterval: number;
29
+ theme: "light" | "dark" | "auto";
30
+ action: string;
31
+ appearance: "always" | "execute" | "interaction-only";
32
+ renderOnMount: boolean;
33
+ }, {}, {}, {}, string, ComponentProvideOptions, false, {
34
+ element: HTMLDivElement;
35
+ }, HTMLDivElement>;
36
+
37
+ export declare interface TurnstileProps {
38
+ sitekey: string;
39
+ modelValue?: string;
40
+ resetInterval?: number;
41
+ size?: 'normal' | 'compact';
42
+ theme?: 'light' | 'dark' | 'auto';
43
+ action?: string;
44
+ appearance?: 'always' | 'execute' | 'interaction-only';
45
+ renderOnMount?: boolean;
46
+ }
47
+
48
+ export { }
package/dist/addons.js ADDED
@@ -0,0 +1,442 @@
1
+ import { defineComponent, createElementBlock, openBlock, createElementVNode, toDisplayString, Fragment, renderList, createVNode, unref, ref, computed, onMounted, withDirectives, createCommentVNode, withKeys, createBlock, mergeProps, withModifiers, vShow, withCtx, createTextVNode, normalizeStyle, useTemplateRef, onBeforeUnmount } from "vue";
2
+ import { Icon } from "@iconify/vue";
3
+ import { TextField, Button, Tooltip, Pagination } from "./components";
4
+ const _hoisted_1$1 = {
5
+ type: "button",
6
+ class: "ui-IconifySample"
7
+ };
8
+ const _hoisted_2$1 = { class: "ui-IconifySampleInfo" };
9
+ const _hoisted_3$1 = { class: "ui-IconifySampleIcons" };
10
+ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
11
+ __name: "IconifySample",
12
+ props: {
13
+ prefix: {},
14
+ category: {},
15
+ name: {},
16
+ samples: {},
17
+ total: {},
18
+ license: {}
19
+ },
20
+ setup(__props) {
21
+ const props = __props;
22
+ return (_ctx, _cache) => {
23
+ return openBlock(), createElementBlock("button", _hoisted_1$1, [
24
+ createElementVNode("div", _hoisted_2$1, [
25
+ createElementVNode("strong", null, toDisplayString(props.name), 1),
26
+ createElementVNode("span", null, toDisplayString(props.license.title), 1),
27
+ createElementVNode("span", null, toDisplayString(props.total) + " icons", 1)
28
+ ]),
29
+ createElementVNode("div", _hoisted_3$1, [
30
+ (openBlock(true), createElementBlock(Fragment, null, renderList(props.samples, (icon) => {
31
+ return openBlock(), createElementBlock("span", { key: icon }, [
32
+ createVNode(unref(Icon), {
33
+ icon: props.prefix + ":" + icon
34
+ }, null, 8, ["icon"])
35
+ ]);
36
+ }), 128))
37
+ ])
38
+ ]);
39
+ };
40
+ }
41
+ });
42
+ const _hoisted_1 = { class: "ui-IconifyCollection" };
43
+ const _hoisted_2 = { class: "ui-IconifyCollectionGroups" };
44
+ const _hoisted_3 = { class: "ui-IconifyCollectionGroupsHead" };
45
+ const _hoisted_4 = { class: "ui-IconifyCollectionForm" };
46
+ const _hoisted_5 = { class: "mb-2" };
47
+ const _hoisted_6 = { class: "font-medium" };
48
+ const _hoisted_7 = { class: "text-sm ml-1" };
49
+ const _hoisted_8 = { class: "ui-IconifyCollectionSampleGrid" };
50
+ const _hoisted_9 = {
51
+ key: 0,
52
+ class: "ui-IconifyCollectionIcons"
53
+ };
54
+ const _hoisted_10 = { class: "ui-IconifyCollectionForm" };
55
+ const _hoisted_11 = {
56
+ key: 0,
57
+ class: "ui-IconifyCollectionSuffixes"
58
+ };
59
+ const _hoisted_12 = ["onClick"];
60
+ const fetchCollections = async () => {
61
+ const apiLink = "https://api.iconify.design/collections";
62
+ const resp = await fetch(apiLink);
63
+ const data = await resp.json();
64
+ const cache = {};
65
+ Object.keys(data).forEach((prefix) => {
66
+ const item = data[prefix];
67
+ if (item.hidden) {
68
+ return;
69
+ }
70
+ if (!cache[item.category]) {
71
+ cache[item.category] = [];
72
+ }
73
+ cache[item.category].push({ ...item, prefix });
74
+ });
75
+ const collections = [];
76
+ Object.keys(cache).forEach((category) => {
77
+ collections.push({
78
+ category,
79
+ items: cache[category]
80
+ });
81
+ });
82
+ return collections;
83
+ };
84
+ const searchIcons = async (query) => {
85
+ const apiLink = `https://api.iconify.design/search?query=${encodeURIComponent(query)}&limit=999`;
86
+ const resp = await fetch(apiLink);
87
+ const data = await resp.json();
88
+ return data.icons;
89
+ };
90
+ const fetchCollectionIcons = async (prefix) => {
91
+ const apiLink = `https://api.iconify.design/collection?prefix=${encodeURIComponent(prefix)}&chars=true&aliases=true`;
92
+ const resp = await fetch(apiLink);
93
+ const data = await resp.json();
94
+ return data;
95
+ };
96
+ const filterIcons = (names, query, suffix) => {
97
+ return names.filter((key) => {
98
+ let match = true;
99
+ if (query && key.indexOf(query) === -1) {
100
+ match = false;
101
+ }
102
+ if (suffix && key.indexOf(`-${suffix}`) === -1) {
103
+ match = false;
104
+ }
105
+ return match;
106
+ });
107
+ };
108
+ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
109
+ __name: "IconifyCollection",
110
+ props: {
111
+ prefix: {},
112
+ search: {},
113
+ perpage: { default: 200 },
114
+ iconSize: { default: 20 }
115
+ },
116
+ emits: ["select"],
117
+ setup(__props, { emit: __emit }) {
118
+ const props = __props;
119
+ const emits = __emit;
120
+ const shouldDisplay = ref("all");
121
+ const groupCollections = ref([]);
122
+ const collectionFilter = ref("");
123
+ const page = ref(1);
124
+ const searchQuery = ref("");
125
+ const searchResultIcons = ref([]);
126
+ const collectionData = ref();
127
+ const collectionQuery = ref("");
128
+ const collectionSuffix = ref("");
129
+ const reset = () => {
130
+ page.value = 1;
131
+ searchQuery.value = "";
132
+ searchResultIcons.value = [];
133
+ collectionData.value = void 0;
134
+ collectionQuery.value = "";
135
+ collectionSuffix.value = "";
136
+ shouldDisplay.value = "all";
137
+ };
138
+ const onSelectIcon = (icon) => {
139
+ emits("select", icon);
140
+ };
141
+ const onSearch = async () => {
142
+ if (searchQuery.value) {
143
+ shouldDisplay.value = "search";
144
+ searchResultIcons.value = await searchIcons(searchQuery.value);
145
+ } else {
146
+ shouldDisplay.value = "all";
147
+ }
148
+ };
149
+ const onSelectPrefix = async (prefix) => {
150
+ collectionData.value = void 0;
151
+ collectionQuery.value = "";
152
+ collectionSuffix.value = "";
153
+ shouldDisplay.value = "collection";
154
+ collectionData.value = await fetchCollectionIcons(prefix);
155
+ };
156
+ const collectionCount = computed(() => {
157
+ let count = 0;
158
+ groupCollections.value.forEach((item) => {
159
+ count += item.items.length;
160
+ });
161
+ return count;
162
+ });
163
+ const visibleCollections = computed(() => {
164
+ if (!collectionFilter.value) {
165
+ return groupCollections.value;
166
+ }
167
+ return groupCollections.value.map((collection) => {
168
+ const items = collection.items.filter((item) => {
169
+ const key = [item.category, item.name, item.prefix].join(" ");
170
+ return key.toLowerCase().indexOf(collectionFilter.value) !== -1;
171
+ });
172
+ return { ...collection, items };
173
+ }).filter((collection) => collection.items.length !== 0);
174
+ });
175
+ const collectionIcons = computed(() => {
176
+ let rv = [];
177
+ if (!collectionData.value) {
178
+ return rv;
179
+ }
180
+ if (collectionData.value.uncategorized) {
181
+ rv = filterIcons(collectionData.value.uncategorized, collectionQuery.value, collectionSuffix.value);
182
+ } else if (collectionData.value.categories) {
183
+ Object.keys(collectionData.value.categories).forEach((category) => {
184
+ const icons = collectionData.value.categories[category];
185
+ filterIcons(icons, collectionQuery.value, collectionSuffix.value).forEach((k) => {
186
+ rv.push(k);
187
+ });
188
+ });
189
+ }
190
+ if (collectionQuery.value && !rv.length && collectionData.value.hidden) {
191
+ rv = filterIcons(collectionData.value.hidden, collectionQuery.value, collectionSuffix.value);
192
+ }
193
+ return rv.map((name) => `${collectionData.value?.prefix}:${name}`);
194
+ });
195
+ const allIcons = computed(() => {
196
+ if (shouldDisplay.value === "search") {
197
+ return searchResultIcons.value;
198
+ } else if (shouldDisplay.value === "collection") {
199
+ return collectionIcons.value;
200
+ } else {
201
+ return [];
202
+ }
203
+ });
204
+ const visibleIcons = computed(() => {
205
+ const start = (page.value - 1) * props.perpage;
206
+ const end = page.value * props.perpage;
207
+ return allIcons.value.slice(start, end);
208
+ });
209
+ const iconSize = computed(() => {
210
+ const size = props.iconSize.toString();
211
+ if (/^\d+/.test(size)) {
212
+ return size + "px";
213
+ } else {
214
+ return size;
215
+ }
216
+ });
217
+ onMounted(async () => {
218
+ if (props.prefix) {
219
+ onSelectPrefix(props.prefix);
220
+ } else if (props.search) {
221
+ searchQuery.value = props.search;
222
+ onSearch();
223
+ }
224
+ groupCollections.value = await fetchCollections();
225
+ });
226
+ return (_ctx, _cache) => {
227
+ return openBlock(), createElementBlock("div", _hoisted_1, [
228
+ withDirectives(createElementVNode("div", _hoisted_2, [
229
+ createElementVNode("section", _hoisted_3, [
230
+ createElementVNode("h1", null, toDisplayString(collectionCount.value) + " icon sets", 1),
231
+ createElementVNode("div", _hoisted_4, [
232
+ createVNode(unref(TextField), {
233
+ modelValue: collectionFilter.value,
234
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => collectionFilter.value = $event),
235
+ placeholder: "Filter icon sets..."
236
+ }, null, 8, ["modelValue"]),
237
+ createVNode(unref(TextField), {
238
+ modelValue: searchQuery.value,
239
+ "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => searchQuery.value = $event),
240
+ placeholder: "Search icons...",
241
+ onKeydown: withKeys(onSearch, ["enter"])
242
+ }, null, 8, ["modelValue"])
243
+ ])
244
+ ]),
245
+ (openBlock(true), createElementBlock(Fragment, null, renderList(visibleCollections.value, (collection) => {
246
+ return openBlock(), createElementBlock("section", {
247
+ key: collection.category,
248
+ class: "ui-IconifyCollectionSample"
249
+ }, [
250
+ createElementVNode("h1", _hoisted_5, [
251
+ createElementVNode("span", _hoisted_6, toDisplayString(collection.category), 1),
252
+ createElementVNode("span", _hoisted_7, "(" + toDisplayString(collection.items.length) + " icon sets)", 1)
253
+ ]),
254
+ createElementVNode("div", _hoisted_8, [
255
+ (openBlock(true), createElementBlock(Fragment, null, renderList(collection.items, (item) => {
256
+ return openBlock(), createBlock(_sfc_main$2, mergeProps({
257
+ key: item.prefix
258
+ }, { ref_for: true }, item, {
259
+ onClick: withModifiers(($event) => onSelectPrefix(item.prefix), ["prevent"])
260
+ }), null, 16, ["onClick"]);
261
+ }), 128))
262
+ ])
263
+ ]);
264
+ }), 128))
265
+ ], 512), [
266
+ [vShow, shouldDisplay.value === "all"]
267
+ ]),
268
+ shouldDisplay.value !== "all" ? (openBlock(), createElementBlock("div", _hoisted_9, [
269
+ createElementVNode("div", _hoisted_10, [
270
+ createVNode(unref(Button), {
271
+ type: "button",
272
+ variant: "surface",
273
+ color: "gray",
274
+ onClick: withModifiers(reset, ["prevent"])
275
+ }, {
276
+ default: withCtx(() => _cache[5] || (_cache[5] = [
277
+ createTextVNode(" Back ")
278
+ ])),
279
+ _: 1,
280
+ __: [5]
281
+ }),
282
+ shouldDisplay.value === "search" ? (openBlock(), createBlock(unref(TextField), {
283
+ key: 0,
284
+ modelValue: searchQuery.value,
285
+ "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => searchQuery.value = $event),
286
+ placeholder: "Search icons...",
287
+ onKeydown: withKeys(onSearch, ["enter"])
288
+ }, null, 8, ["modelValue"])) : createCommentVNode("", true),
289
+ shouldDisplay.value === "collection" ? (openBlock(), createBlock(unref(TextField), {
290
+ key: 1,
291
+ modelValue: collectionQuery.value,
292
+ "onUpdate:modelValue": _cache[3] || (_cache[3] = ($event) => collectionQuery.value = $event),
293
+ placeholder: "Search icons..."
294
+ }, null, 8, ["modelValue"])) : createCommentVNode("", true)
295
+ ]),
296
+ shouldDisplay.value === "collection" && collectionData.value?.suffixes ? (openBlock(), createElementBlock("div", _hoisted_11, [
297
+ (openBlock(true), createElementBlock(Fragment, null, renderList(collectionData.value.suffixes, (k, v) => {
298
+ return openBlock(), createBlock(unref(Button), {
299
+ key: v,
300
+ variant: collectionSuffix.value === v ? "solid" : "outline",
301
+ color: "gray",
302
+ "high-contrast": "",
303
+ radius: "full",
304
+ onClick: withModifiers(($event) => collectionSuffix.value = v, ["prevent"])
305
+ }, {
306
+ default: withCtx(() => [
307
+ createTextVNode(toDisplayString(k), 1)
308
+ ]),
309
+ _: 2
310
+ }, 1032, ["variant", "onClick"]);
311
+ }), 128))
312
+ ])) : createCommentVNode("", true),
313
+ createElementVNode("div", {
314
+ class: "ui-IconifyCollectionIconGrid",
315
+ style: normalizeStyle({ fontSize: iconSize.value })
316
+ }, [
317
+ (openBlock(true), createElementBlock(Fragment, null, renderList(visibleIcons.value, (icon) => {
318
+ return openBlock(), createBlock(unref(Tooltip), {
319
+ key: icon,
320
+ as: "div",
321
+ content: icon
322
+ }, {
323
+ default: withCtx(() => [
324
+ createElementVNode("button", {
325
+ type: "button",
326
+ onClick: withModifiers(($event) => onSelectIcon(icon), ["prevent"])
327
+ }, [
328
+ createVNode(unref(Icon), { icon }, null, 8, ["icon"])
329
+ ], 8, _hoisted_12)
330
+ ]),
331
+ _: 2
332
+ }, 1032, ["content"]);
333
+ }), 128))
334
+ ], 4),
335
+ createVNode(unref(Pagination), {
336
+ page: page.value,
337
+ "onUpdate:page": _cache[4] || (_cache[4] = ($event) => page.value = $event),
338
+ total: allIcons.value.length,
339
+ perpage: _ctx.perpage,
340
+ size: "2"
341
+ }, null, 8, ["page", "total", "perpage"])
342
+ ])) : createCommentVNode("", true)
343
+ ]);
344
+ };
345
+ }
346
+ });
347
+ const turnstileSrc = "https://challenges.cloudflare.com/turnstile/v0/api.js";
348
+ const turnstileLoadFunction = "cfTurnstileOnLoad";
349
+ let turnstileState = typeof window !== "undefined" ? window.turnstile !== void 0 ? "ready" : "unloaded" : "unloaded";
350
+ let turnstileLoad;
351
+ let widgetId;
352
+ let resetTimeout;
353
+ const _sfc_main = /* @__PURE__ */ defineComponent({
354
+ __name: "Turnstile",
355
+ props: {
356
+ sitekey: {},
357
+ modelValue: {},
358
+ resetInterval: { default: 295 * 1e3 },
359
+ size: { default: "normal" },
360
+ theme: { default: "auto" },
361
+ action: { default: "" },
362
+ appearance: { default: "always" },
363
+ renderOnMount: { type: Boolean, default: true }
364
+ },
365
+ emits: ["update:modelValue"],
366
+ setup(__props, { emit: __emit }) {
367
+ const props = __props;
368
+ const emit = __emit;
369
+ const element = useTemplateRef("element");
370
+ const resetTurnstile = () => {
371
+ if (window.turnstile) {
372
+ emit("update:modelValue", "");
373
+ window.turnstile.reset();
374
+ }
375
+ };
376
+ const removeTurnstile = () => {
377
+ if (widgetId) {
378
+ window.turnstile.remove(widgetId);
379
+ widgetId = void 0;
380
+ }
381
+ };
382
+ const callbackTurnstile = (token) => {
383
+ emit("update:modelValue", token);
384
+ resetTimeout = setTimeout(() => {
385
+ resetTurnstile();
386
+ }, props.resetInterval);
387
+ };
388
+ const renderTurnstile = () => {
389
+ widgetId = window.turnstile.render(element.value, {
390
+ sitekey: props.sitekey,
391
+ theme: props.theme,
392
+ size: props.size,
393
+ callback: callbackTurnstile,
394
+ action: props.action,
395
+ appearance: props.appearance
396
+ });
397
+ };
398
+ onMounted(async () => {
399
+ const turnstileLoadPromise = new Promise((resolve, reject) => {
400
+ turnstileLoad = { resolve, reject };
401
+ if (turnstileState === "ready") resolve(void 0);
402
+ });
403
+ window[turnstileLoadFunction] = () => {
404
+ turnstileLoad.resolve();
405
+ turnstileState = "ready";
406
+ };
407
+ const ensureTurnstile = () => {
408
+ if (turnstileState === "unloaded") {
409
+ turnstileState = "loading";
410
+ const url = `${turnstileSrc}?onload=${turnstileLoadFunction}&render=explicit`;
411
+ const script = document.createElement("script");
412
+ script.src = url;
413
+ script.async = true;
414
+ script.addEventListener("error", () => {
415
+ turnstileLoad.reject("Failed to load Turnstile.");
416
+ });
417
+ document.head.appendChild(script);
418
+ }
419
+ return turnstileLoadPromise;
420
+ };
421
+ await ensureTurnstile();
422
+ if (props.renderOnMount) {
423
+ renderTurnstile();
424
+ }
425
+ });
426
+ onBeforeUnmount(() => {
427
+ removeTurnstile();
428
+ clearTimeout(resetTimeout);
429
+ });
430
+ return (_ctx, _cache) => {
431
+ return openBlock(), createElementBlock("div", {
432
+ ref_key: "element",
433
+ ref: element,
434
+ class: "ui-Turnstile"
435
+ }, null, 512);
436
+ };
437
+ }
438
+ });
439
+ export {
440
+ _sfc_main$1 as IconifyCollection,
441
+ _sfc_main as Turnstile
442
+ };