@vesk/runtime 0.0.1
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/README.md +23 -0
- package/dist/action.d.ts +43 -0
- package/dist/action.d.ts.map +1 -0
- package/dist/action.js +84 -0
- package/dist/bindings.d.ts +4 -0
- package/dist/bindings.d.ts.map +1 -0
- package/dist/bindings.js +137 -0
- package/dist/context.d.ts +15 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +34 -0
- package/dist/experiment.d.ts +17 -0
- package/dist/experiment.d.ts.map +1 -0
- package/dist/experiment.js +71 -0
- package/dist/form.d.ts +36 -0
- package/dist/form.d.ts.map +1 -0
- package/dist/form.js +278 -0
- package/dist/hmr-client.d.ts +1 -0
- package/dist/hmr-client.d.ts.map +1 -0
- package/dist/hmr-client.js +273 -0
- package/dist/hydrate.d.ts +34 -0
- package/dist/hydrate.d.ts.map +1 -0
- package/dist/hydrate.js +248 -0
- package/dist/image.d.ts +19 -0
- package/dist/image.d.ts.map +1 -0
- package/dist/image.js +51 -0
- package/dist/index-client.d.ts +16 -0
- package/dist/index-client.d.ts.map +1 -0
- package/dist/index-client.js +15 -0
- package/dist/index-server.d.ts +15 -0
- package/dist/index-server.d.ts.map +1 -0
- package/dist/index-server.js +14 -0
- package/dist/isr.d.ts +27 -0
- package/dist/isr.d.ts.map +1 -0
- package/dist/isr.js +143 -0
- package/dist/md.d.ts +17 -0
- package/dist/md.d.ts.map +1 -0
- package/dist/md.js +507 -0
- package/dist/package.json +23 -0
- package/dist/portal.d.ts +8 -0
- package/dist/portal.d.ts.map +1 -0
- package/dist/portal.js +20 -0
- package/dist/reconcile.d.ts +3 -0
- package/dist/reconcile.d.ts.map +1 -0
- package/dist/reconcile.js +66 -0
- package/dist/request.d.ts +188 -0
- package/dist/request.d.ts.map +1 -0
- package/dist/request.js +624 -0
- package/dist/resource.d.ts +47 -0
- package/dist/resource.d.ts.map +1 -0
- package/dist/resource.js +502 -0
- package/dist/ripple-blocks.d.ts +18 -0
- package/dist/ripple-blocks.d.ts.map +1 -0
- package/dist/ripple-blocks.js +184 -0
- package/dist/ripple-constants.d.ts +42 -0
- package/dist/ripple-constants.d.ts.map +1 -0
- package/dist/ripple-constants.js +41 -0
- package/dist/ripple-runtime.d.ts +125 -0
- package/dist/ripple-runtime.d.ts.map +1 -0
- package/dist/ripple-runtime.js +891 -0
- package/dist/ripple-utils.d.ts +12 -0
- package/dist/ripple-utils.d.ts.map +1 -0
- package/dist/ripple-utils.js +10 -0
- package/dist/router-components.d.ts +83 -0
- package/dist/router-components.d.ts.map +1 -0
- package/dist/router-components.js +320 -0
- package/dist/router-match.d.ts +40 -0
- package/dist/router-match.d.ts.map +1 -0
- package/dist/router-match.js +158 -0
- package/dist/router.d.ts +56 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/router.js +1330 -0
- package/dist/seo.d.ts +94 -0
- package/dist/seo.d.ts.map +1 -0
- package/dist/seo.js +138 -0
- package/dist/suspense.d.ts +1 -0
- package/dist/suspense.d.ts.map +1 -0
- package/dist/suspense.js +14 -0
- package/dist/track.d.ts +20 -0
- package/dist/track.d.ts.map +1 -0
- package/dist/track.js +124 -0
- package/package.json +55 -0
package/dist/seo.d.ts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
interface JsonLdProps {
|
|
2
|
+
schema?: Record<string, unknown>;
|
|
3
|
+
children?: Record<string, unknown>;
|
|
4
|
+
key?: string;
|
|
5
|
+
[k: string]: unknown;
|
|
6
|
+
}
|
|
7
|
+
export declare function JsonLd(props: JsonLdProps): string | null;
|
|
8
|
+
interface ArticleData {
|
|
9
|
+
headline: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
author: string | string[];
|
|
12
|
+
datePublished: string;
|
|
13
|
+
dateModified?: string;
|
|
14
|
+
image?: string | string[];
|
|
15
|
+
publisher?: string;
|
|
16
|
+
url?: string;
|
|
17
|
+
}
|
|
18
|
+
export declare function ArticleSchema(article: ArticleData): Record<string, unknown>;
|
|
19
|
+
interface ProductData {
|
|
20
|
+
name: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
image?: string | string[];
|
|
23
|
+
sku?: string;
|
|
24
|
+
brand?: string;
|
|
25
|
+
price?: string;
|
|
26
|
+
currency?: string;
|
|
27
|
+
inStock?: boolean;
|
|
28
|
+
url?: string;
|
|
29
|
+
reviews?: {
|
|
30
|
+
rating: number;
|
|
31
|
+
author: string;
|
|
32
|
+
body?: string;
|
|
33
|
+
}[];
|
|
34
|
+
aggregateRating?: {
|
|
35
|
+
value: number;
|
|
36
|
+
count: number;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export declare function ProductSchema(product: ProductData): Record<string, unknown>;
|
|
40
|
+
interface FAQItem {
|
|
41
|
+
question: string;
|
|
42
|
+
answer: string;
|
|
43
|
+
}
|
|
44
|
+
export declare function FAQPageSchema(faqs: FAQItem[]): Record<string, unknown>;
|
|
45
|
+
interface BreadcrumbItem {
|
|
46
|
+
name: string;
|
|
47
|
+
url: string;
|
|
48
|
+
}
|
|
49
|
+
export declare function BreadcrumbListSchema(items: BreadcrumbItem[]): Record<string, unknown>;
|
|
50
|
+
interface OrganizationData {
|
|
51
|
+
type?: string;
|
|
52
|
+
name: string;
|
|
53
|
+
url?: string;
|
|
54
|
+
logo?: string;
|
|
55
|
+
description?: string;
|
|
56
|
+
sameAs?: string[];
|
|
57
|
+
contactPoint?: {
|
|
58
|
+
telephone: string;
|
|
59
|
+
contactType?: string;
|
|
60
|
+
email?: string;
|
|
61
|
+
};
|
|
62
|
+
address?: {
|
|
63
|
+
streetAddress?: string;
|
|
64
|
+
addressLocality?: string;
|
|
65
|
+
addressRegion?: string;
|
|
66
|
+
postalCode?: string;
|
|
67
|
+
addressCountry?: string;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export declare function OrganizationSchema(org: OrganizationData): Record<string, unknown>;
|
|
71
|
+
interface LocalBusinessData extends OrganizationData {
|
|
72
|
+
subtype?: string;
|
|
73
|
+
hours?: {
|
|
74
|
+
days: string;
|
|
75
|
+
open: string;
|
|
76
|
+
close: string;
|
|
77
|
+
}[];
|
|
78
|
+
priceRange?: string;
|
|
79
|
+
telephone?: string;
|
|
80
|
+
}
|
|
81
|
+
export declare function LocalBusinessSchema(biz: LocalBusinessData): Record<string, unknown>;
|
|
82
|
+
interface VideoData {
|
|
83
|
+
name: string;
|
|
84
|
+
description?: string;
|
|
85
|
+
thumbnailUrl?: string | string[];
|
|
86
|
+
uploadDate?: string;
|
|
87
|
+
duration?: string;
|
|
88
|
+
contentUrl?: string;
|
|
89
|
+
embedUrl?: string;
|
|
90
|
+
viewCount?: number;
|
|
91
|
+
}
|
|
92
|
+
export declare function VideoSchema(video: VideoData): Record<string, unknown>;
|
|
93
|
+
export {};
|
|
94
|
+
//# sourceMappingURL=seo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seo.d.ts","sourceRoot":"","sources":["../src/seo.ts"],"names":[],"mappings":"AAAA,UAAU,WAAW;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACrB;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,GAAG,IAAI,CAiBxD;AAED,UAAU,WAAW;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CA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AClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAgBrE"}
|
package/dist/seo.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
export function JsonLd(props) {
|
|
2
|
+
const schema = props.schema || props.children || {};
|
|
3
|
+
const json = JSON.stringify({
|
|
4
|
+
'@context': 'https://schema.org',
|
|
5
|
+
...schema,
|
|
6
|
+
});
|
|
7
|
+
if (typeof document === 'undefined') {
|
|
8
|
+
return `<script type="application/ld+json">${json.replace(/<\/script>/g, '<\\/script>')}</script>`;
|
|
9
|
+
}
|
|
10
|
+
if (!document.querySelector(`script[type="application/ld+json"][data-key="${props.key || ''}"]`)) {
|
|
11
|
+
const el = document.createElement('script');
|
|
12
|
+
el.type = 'application/ld+json';
|
|
13
|
+
el.textContent = json;
|
|
14
|
+
if (props.key)
|
|
15
|
+
el.setAttribute('data-key', props.key);
|
|
16
|
+
document.head.appendChild(el);
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
export function ArticleSchema(article) {
|
|
21
|
+
return {
|
|
22
|
+
'@type': 'Article',
|
|
23
|
+
headline: article.headline,
|
|
24
|
+
description: article.description,
|
|
25
|
+
author: Array.isArray(article.author)
|
|
26
|
+
? article.author.map(a => ({ '@type': 'Person', name: a }))
|
|
27
|
+
: { '@type': 'Person', name: article.author },
|
|
28
|
+
datePublished: article.datePublished,
|
|
29
|
+
dateModified: article.dateModified || article.datePublished,
|
|
30
|
+
image: article.image ? (Array.isArray(article.image) ? article.image : [article.image]) : undefined,
|
|
31
|
+
publisher: article.publisher || undefined,
|
|
32
|
+
mainEntityOfPage: article.url ? { '@type': 'WebPage', '@id': article.url } : undefined,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export function ProductSchema(product) {
|
|
36
|
+
return {
|
|
37
|
+
'@type': 'Product',
|
|
38
|
+
name: product.name,
|
|
39
|
+
description: product.description,
|
|
40
|
+
image: product.image ? (Array.isArray(product.image) ? product.image : [product.image]) : undefined,
|
|
41
|
+
sku: product.sku,
|
|
42
|
+
brand: product.brand ? { '@type': 'Brand', name: product.brand } : undefined,
|
|
43
|
+
offers: {
|
|
44
|
+
'@type': 'Offer',
|
|
45
|
+
price: product.price,
|
|
46
|
+
priceCurrency: product.currency || 'USD',
|
|
47
|
+
availability: product.inStock ? 'https://schema.org/InStock' : 'https://schema.org/OutOfStock',
|
|
48
|
+
url: product.url,
|
|
49
|
+
},
|
|
50
|
+
review: product.reviews ? product.reviews.map(r => ({
|
|
51
|
+
'@type': 'Review',
|
|
52
|
+
reviewRating: { '@type': 'Rating', ratingValue: r.rating },
|
|
53
|
+
author: { '@type': 'Person', name: r.author },
|
|
54
|
+
reviewBody: r.body,
|
|
55
|
+
})) : undefined,
|
|
56
|
+
aggregateRating: product.aggregateRating ? {
|
|
57
|
+
'@type': 'AggregateRating',
|
|
58
|
+
ratingValue: product.aggregateRating.value,
|
|
59
|
+
reviewCount: product.aggregateRating.count,
|
|
60
|
+
} : undefined,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
export function FAQPageSchema(faqs) {
|
|
64
|
+
return {
|
|
65
|
+
'@type': 'FAQPage',
|
|
66
|
+
mainEntity: faqs.map(f => ({
|
|
67
|
+
'@type': 'Question',
|
|
68
|
+
name: f.question,
|
|
69
|
+
acceptedAnswer: { '@type': 'Answer', text: f.answer },
|
|
70
|
+
})),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
export function BreadcrumbListSchema(items) {
|
|
74
|
+
return {
|
|
75
|
+
'@type': 'BreadcrumbList',
|
|
76
|
+
itemListElement: items.map((item, i) => ({
|
|
77
|
+
'@type': 'ListItem',
|
|
78
|
+
position: i + 1,
|
|
79
|
+
name: item.name,
|
|
80
|
+
item: item.url,
|
|
81
|
+
})),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
export function OrganizationSchema(org) {
|
|
85
|
+
return {
|
|
86
|
+
'@type': org.type || 'Organization',
|
|
87
|
+
name: org.name,
|
|
88
|
+
url: org.url,
|
|
89
|
+
logo: org.logo,
|
|
90
|
+
description: org.description,
|
|
91
|
+
sameAs: org.sameAs || undefined,
|
|
92
|
+
contactPoint: org.contactPoint ? {
|
|
93
|
+
'@type': 'ContactPoint',
|
|
94
|
+
telephone: org.contactPoint.telephone,
|
|
95
|
+
contactType: org.contactPoint.contactType || 'customer service',
|
|
96
|
+
email: org.contactPoint.email,
|
|
97
|
+
} : undefined,
|
|
98
|
+
address: org.address ? {
|
|
99
|
+
'@type': 'PostalAddress',
|
|
100
|
+
streetAddress: org.address.streetAddress,
|
|
101
|
+
addressLocality: org.address.addressLocality,
|
|
102
|
+
addressRegion: org.address.addressRegion,
|
|
103
|
+
postalCode: org.address.postalCode,
|
|
104
|
+
addressCountry: org.address.addressCountry,
|
|
105
|
+
} : undefined,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
export function LocalBusinessSchema(biz) {
|
|
109
|
+
return {
|
|
110
|
+
...OrganizationSchema(biz),
|
|
111
|
+
'@type': biz.subtype || 'LocalBusiness',
|
|
112
|
+
openingHoursSpecification: biz.hours ? biz.hours.map(h => ({
|
|
113
|
+
'@type': 'OpeningHoursSpecification',
|
|
114
|
+
dayOfWeek: h.days,
|
|
115
|
+
opens: h.open,
|
|
116
|
+
closes: h.close,
|
|
117
|
+
})) : undefined,
|
|
118
|
+
priceRange: biz.priceRange,
|
|
119
|
+
telephone: biz.telephone,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
export function VideoSchema(video) {
|
|
123
|
+
return {
|
|
124
|
+
'@type': 'VideoObject',
|
|
125
|
+
name: video.name,
|
|
126
|
+
description: video.description,
|
|
127
|
+
thumbnailUrl: video.thumbnailUrl ? (Array.isArray(video.thumbnailUrl) ? video.thumbnailUrl : [video.thumbnailUrl]) : undefined,
|
|
128
|
+
uploadDate: video.uploadDate,
|
|
129
|
+
duration: video.duration,
|
|
130
|
+
contentUrl: video.contentUrl,
|
|
131
|
+
embedUrl: video.embedUrl,
|
|
132
|
+
interactionStatistic: video.viewCount ? {
|
|
133
|
+
'@type': 'InteractionCounter',
|
|
134
|
+
interactionType: 'https://schema.org/WatchAction',
|
|
135
|
+
userInteractionCount: video.viewCount,
|
|
136
|
+
} : undefined,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=suspense.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"suspense.d.ts","sourceRoot":"","sources":["../src/suspense.ts"],"names":[],"mappings":""}
|
package/dist/suspense.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Suspense requires compiler-level support to create the boundary
|
|
3
|
+
// before children are evaluated (children are pre-evaluated by
|
|
4
|
+
// emitComponentCall before the component function runs).
|
|
5
|
+
//
|
|
6
|
+
// For now, use the `if (loading)` pattern with createResource:
|
|
7
|
+
// const &[data] = createResource(fetchData);
|
|
8
|
+
// if (data) return <div>{data}</div>;
|
|
9
|
+
// return <p>Loading...</p>;
|
|
10
|
+
//
|
|
11
|
+
// This compiles to OpaqueDynamicRegion and works reactively.
|
|
12
|
+
//
|
|
13
|
+
// Full Suspense with coordinated boundaries across multiple resources
|
|
14
|
+
// will be added as a compiler intrinsic in a future phase.
|
package/dist/track.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare class Cell<T> {
|
|
2
|
+
#private;
|
|
3
|
+
constructor(initialValue: T);
|
|
4
|
+
get(): T;
|
|
5
|
+
peek(): T;
|
|
6
|
+
set(newValue: T): boolean;
|
|
7
|
+
update(fn: (current: T) => T): boolean;
|
|
8
|
+
unsubscribe(effect: Effect): void;
|
|
9
|
+
}
|
|
10
|
+
export declare class Effect {
|
|
11
|
+
#private;
|
|
12
|
+
constructor(fn: () => void);
|
|
13
|
+
run(): void;
|
|
14
|
+
destroy(): void;
|
|
15
|
+
}
|
|
16
|
+
export declare function track<T>(initialValue: T): Cell<T>;
|
|
17
|
+
export declare function effect(fn: () => void): Effect;
|
|
18
|
+
export declare function batch<T>(fn: () => T): T;
|
|
19
|
+
export declare function derived<T>(fn: () => T): Cell<T>;
|
|
20
|
+
//# sourceMappingURL=track.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"track.d.ts","sourceRoot":"","sources":["../src/track.ts"],"names":[],"mappings":"AAKA,qBAAa,IAAI,CAAC,CAAC;;gBAIN,YAAY,EAAE,CAAC;IAI3B,GAAG,IAAI,CAAC;IAQR,IAAI,IAAI,CAAC;IAIT,GAAG,CAAC,QAAQ,EAAE,CAAC,GAAG,OAAO;IAOzB,MAAM,CAAC,EAAE,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,GAAG,OAAO;IAItC,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;CAiBjC;AAED,qBAAa,MAAM;;gBAMN,EAAE,EAAE,MAAM,IAAI;IAK1B,GAAG,IAAI,IAAI;IA2BX,OAAO,IAAI,IAAI;CAQf;AAED,wBAAgB,KAAK,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAEjD;AAED,wBAAgB,MAAM,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,MAAM,CAE7C;AAED,wBAAgB,KAAK,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAmBvC;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAM/C"}
|
package/dist/track.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
let currentEffect = null;
|
|
2
|
+
let currentDeps = null;
|
|
3
|
+
let batchDepth = 0;
|
|
4
|
+
const batchQueue = [];
|
|
5
|
+
export class Cell {
|
|
6
|
+
#value;
|
|
7
|
+
#subscribers = new Set();
|
|
8
|
+
constructor(initialValue) {
|
|
9
|
+
this.#value = initialValue;
|
|
10
|
+
}
|
|
11
|
+
get() {
|
|
12
|
+
if (currentEffect) {
|
|
13
|
+
this.#subscribers.add(currentEffect);
|
|
14
|
+
currentDeps?.add(this);
|
|
15
|
+
}
|
|
16
|
+
return this.#value;
|
|
17
|
+
}
|
|
18
|
+
peek() {
|
|
19
|
+
return this.#value;
|
|
20
|
+
}
|
|
21
|
+
set(newValue) {
|
|
22
|
+
if (Object.is(this.#value, newValue))
|
|
23
|
+
return false;
|
|
24
|
+
this.#value = newValue;
|
|
25
|
+
this.#notify();
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
update(fn) {
|
|
29
|
+
return this.set(fn(this.#value));
|
|
30
|
+
}
|
|
31
|
+
unsubscribe(effect) {
|
|
32
|
+
this.#subscribers.delete(effect);
|
|
33
|
+
}
|
|
34
|
+
#notify() {
|
|
35
|
+
if (batchDepth > 0) {
|
|
36
|
+
const queue = batchQueue[batchQueue.length - 1];
|
|
37
|
+
for (const sub of this.#subscribers) {
|
|
38
|
+
queue.add(sub);
|
|
39
|
+
}
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const subs = Array.from(this.#subscribers);
|
|
43
|
+
for (const effect of subs) {
|
|
44
|
+
effect.run();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export class Effect {
|
|
49
|
+
#fn;
|
|
50
|
+
#deps = new Set();
|
|
51
|
+
#active = false;
|
|
52
|
+
#destroyed = false;
|
|
53
|
+
constructor(fn) {
|
|
54
|
+
this.#fn = fn;
|
|
55
|
+
this.run();
|
|
56
|
+
}
|
|
57
|
+
run() {
|
|
58
|
+
if (this.#destroyed)
|
|
59
|
+
return;
|
|
60
|
+
if (!this.#active && batchDepth > 0) {
|
|
61
|
+
batchQueue[batchQueue.length - 1].add(this);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
for (const cell of this.#deps) {
|
|
65
|
+
cell.unsubscribe(this);
|
|
66
|
+
}
|
|
67
|
+
const prev = currentEffect;
|
|
68
|
+
const prevDeps = currentDeps;
|
|
69
|
+
currentEffect = this;
|
|
70
|
+
currentDeps = new Set();
|
|
71
|
+
try {
|
|
72
|
+
this.#fn();
|
|
73
|
+
}
|
|
74
|
+
finally {
|
|
75
|
+
this.#deps = currentDeps;
|
|
76
|
+
currentEffect = prev;
|
|
77
|
+
currentDeps = prevDeps;
|
|
78
|
+
}
|
|
79
|
+
this.#active = true;
|
|
80
|
+
}
|
|
81
|
+
destroy() {
|
|
82
|
+
for (const cell of this.#deps) {
|
|
83
|
+
cell.unsubscribe(this);
|
|
84
|
+
}
|
|
85
|
+
this.#deps.clear();
|
|
86
|
+
this.#active = false;
|
|
87
|
+
this.#destroyed = true;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
export function track(initialValue) {
|
|
91
|
+
return new Cell(initialValue);
|
|
92
|
+
}
|
|
93
|
+
export function effect(fn) {
|
|
94
|
+
return new Effect(fn);
|
|
95
|
+
}
|
|
96
|
+
export function batch(fn) {
|
|
97
|
+
batchDepth++;
|
|
98
|
+
batchQueue.push(new Set());
|
|
99
|
+
try {
|
|
100
|
+
return fn();
|
|
101
|
+
}
|
|
102
|
+
finally {
|
|
103
|
+
const pending = batchQueue.pop();
|
|
104
|
+
batchDepth--;
|
|
105
|
+
if (batchDepth === 0 && pending) {
|
|
106
|
+
for (const e of pending) {
|
|
107
|
+
e.run();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else if (batchDepth > 0 && pending) {
|
|
111
|
+
const parentQueue = batchQueue[batchQueue.length - 1];
|
|
112
|
+
for (const e of pending) {
|
|
113
|
+
parentQueue.add(e);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
export function derived(fn) {
|
|
119
|
+
const cell = track(undefined);
|
|
120
|
+
effect(() => {
|
|
121
|
+
cell.set(fn());
|
|
122
|
+
});
|
|
123
|
+
return cell;
|
|
124
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vesk/runtime",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Vesk runtime — reactivity, blocks, DOM operations, hydration",
|
|
6
|
+
"main": "./dist/index-client.js",
|
|
7
|
+
"types": "./dist/index-client.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index-client.d.ts",
|
|
11
|
+
"default": "./dist/index-client.js"
|
|
12
|
+
},
|
|
13
|
+
"./client": {
|
|
14
|
+
"types": "./dist/index-client.d.ts",
|
|
15
|
+
"default": "./dist/index-client.js"
|
|
16
|
+
},
|
|
17
|
+
"./server": {
|
|
18
|
+
"types": "./dist/index-server.d.ts",
|
|
19
|
+
"default": "./dist/index-server.js"
|
|
20
|
+
},
|
|
21
|
+
"./src/*": "./dist/*.js",
|
|
22
|
+
"./package.json": "./package.json"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@vesk/compiler": "^0.0.1"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"typecheck": "tsc --noEmit",
|
|
29
|
+
"build": "tsc -p tsconfig.build.json",
|
|
30
|
+
"prepublishOnly": "npm run build"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"typescript": "^5.8.0"
|
|
34
|
+
},
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"author": "emeraldlinks",
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "https://github.com/emeraldlinks/veskTs.git"
|
|
40
|
+
},
|
|
41
|
+
"homepage": "https://github.com/emeraldlinks/veskTs#readme",
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://github.com/emeraldlinks/veskTs/issues"
|
|
44
|
+
},
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=20.0.0"
|
|
47
|
+
},
|
|
48
|
+
"files": [
|
|
49
|
+
"dist",
|
|
50
|
+
"README.md"
|
|
51
|
+
],
|
|
52
|
+
"publishConfig": {
|
|
53
|
+
"access": "public"
|
|
54
|
+
}
|
|
55
|
+
}
|