@sprlab/wccompiler 0.12.1 → 0.14.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.
@@ -1,68 +1,68 @@
1
- /**
2
- * wcc-runtime.js — Optional reactive binding helper for consuming wcc components.
3
- * This is NOT required. Components are 100% native and work without it.
4
- * It provides declarative :prop and @event bindings in HTML.
5
- */
6
- const state = {};
7
- const listeners = [];
8
- const handlers = {};
9
-
10
- /**
11
- * Initialize the runtime with an initial state and bind :prop and @event attributes.
12
- *
13
- * @param {Record<string, any>} initialState
14
- * @returns {void}
15
- */
16
- export function init(initialState) {
17
- Object.assign(state, initialState);
18
- document.querySelectorAll('*').forEach(el => {
19
- for (const attr of Array.from(el.attributes)) {
20
- if (attr.name.startsWith(':')) {
21
- const prop = attr.name.slice(1);
22
- const key = attr.value;
23
- listeners.push({ key, update: (val) => { el[prop] = val; } });
24
- if (key in state) el[prop] = state[key];
25
- }
26
- if (attr.name.startsWith('@')) {
27
- const event = attr.name.slice(1);
28
- const handlerName = attr.value;
29
- el.addEventListener(event, (e) => {
30
- if (handlers[handlerName]) handlers[handlerName](e);
31
- });
32
- }
33
- }
34
- });
35
- }
36
-
37
- /**
38
- * Set a state value and notify all listeners bound to that key.
39
- *
40
- * @param {string} key
41
- * @param {any} value
42
- * @returns {void}
43
- */
44
- export function set(key, value) {
45
- state[key] = value;
46
- listeners.filter(l => l.key === key).forEach(l => l.update(state[key]));
47
- }
48
-
49
- /**
50
- * Get the current value for a state key.
51
- *
52
- * @param {string} key
53
- * @returns {any}
54
- */
55
- export function get(key) {
56
- return state[key];
57
- }
58
-
59
- /**
60
- * Register a named event handler.
61
- *
62
- * @param {string} name
63
- * @param {Function} fn
64
- * @returns {void}
65
- */
66
- export function on(name, fn) {
67
- handlers[name] = fn;
68
- }
1
+ /**
2
+ * wcc-runtime.js — Optional reactive binding helper for consuming wcc components.
3
+ * This is NOT required. Components are 100% native and work without it.
4
+ * It provides declarative :prop and @event bindings in HTML.
5
+ */
6
+ const state = {};
7
+ const listeners = [];
8
+ const handlers = {};
9
+
10
+ /**
11
+ * Initialize the runtime with an initial state and bind :prop and @event attributes.
12
+ *
13
+ * @param {Record<string, any>} initialState
14
+ * @returns {void}
15
+ */
16
+ export function init(initialState) {
17
+ Object.assign(state, initialState);
18
+ document.querySelectorAll('*').forEach(el => {
19
+ for (const attr of Array.from(el.attributes)) {
20
+ if (attr.name.startsWith(':')) {
21
+ const prop = attr.name.slice(1);
22
+ const key = attr.value;
23
+ listeners.push({ key, update: (val) => { el[prop] = val; } });
24
+ if (key in state) el[prop] = state[key];
25
+ }
26
+ if (attr.name.startsWith('@')) {
27
+ const event = attr.name.slice(1);
28
+ const handlerName = attr.value;
29
+ el.addEventListener(event, (e) => {
30
+ if (handlers[handlerName]) handlers[handlerName](e);
31
+ });
32
+ }
33
+ }
34
+ });
35
+ }
36
+
37
+ /**
38
+ * Set a state value and notify all listeners bound to that key.
39
+ *
40
+ * @param {string} key
41
+ * @param {any} value
42
+ * @returns {void}
43
+ */
44
+ export function set(key, value) {
45
+ state[key] = value;
46
+ listeners.filter(l => l.key === key).forEach(l => l.update(state[key]));
47
+ }
48
+
49
+ /**
50
+ * Get the current value for a state key.
51
+ *
52
+ * @param {string} key
53
+ * @returns {any}
54
+ */
55
+ export function get(key) {
56
+ return state[key];
57
+ }
58
+
59
+ /**
60
+ * Register a named event handler.
61
+ *
62
+ * @param {string} name
63
+ * @param {Function} fn
64
+ * @returns {void}
65
+ */
66
+ export function on(name, fn) {
67
+ handlers[name] = fn;
68
+ }
package/package.json CHANGED
@@ -1,85 +1,85 @@
1
- {
2
- "name": "@sprlab/wccompiler",
3
- "version": "0.12.1",
4
- "description": "Zero-runtime compiler that transforms .wcc single-file components into native web components with signals-based reactivity",
5
- "type": "module",
6
- "exports": {
7
- ".": "./lib/compiler.js",
8
- "./integrations/vue": "./integrations/vue.js",
9
- "./integrations/react": "./integrations/react.js",
10
- "./integrations/angular": "./integrations/angular.js",
11
- "./adapters/vue": "./adapters/vue.js",
12
- "./adapters/angular": {
13
- "types": "./adapters/angular-compiled/angular.d.ts",
14
- "default": "./adapters/angular-compiled/angular.mjs"
15
- },
16
- "./adapters/react": "./adapters/react.js"
17
- },
18
- "bin": {
19
- "wcc": "./bin/wcc.js"
20
- },
21
- "files": [
22
- "bin/",
23
- "lib/*.js",
24
- "!lib/*.test.js",
25
- "integrations/",
26
- "adapters/",
27
- "types/",
28
- "README.md"
29
- ],
30
- "types": "./types/wcc.d.ts",
31
- "scripts": {
32
- "test": "vitest --run",
33
- "typecheck": "tsc --project jsconfig.json --noEmit"
34
- },
35
- "keywords": [
36
- "web-components",
37
- "compiler",
38
- "custom-elements",
39
- "zero-runtime",
40
- "signals",
41
- "native"
42
- ],
43
- "license": "MIT",
44
- "publishConfig": {
45
- "access": "public"
46
- },
47
- "dependencies": {
48
- "@babel/generator": "^7.27.0",
49
- "@babel/parser": "^7.27.0",
50
- "@babel/traverse": "^7.27.0",
51
- "@babel/types": "^7.27.0",
52
- "esbuild": "^0.27.0",
53
- "linkedom": "^0.18.12"
54
- },
55
- "peerDependencies": {
56
- "@angular/core": ">=14.0.0",
57
- "@vitejs/plugin-vue": ">=4.0.0",
58
- "react": ">=18.0.0",
59
- "vue": ">=3.0.0"
60
- },
61
- "peerDependenciesMeta": {
62
- "@angular/core": {
63
- "optional": true
64
- },
65
- "@vitejs/plugin-vue": {
66
- "optional": true
67
- },
68
- "react": {
69
- "optional": true
70
- },
71
- "vue": {
72
- "optional": true
73
- }
74
- },
75
- "devDependencies": {
76
- "fast-check": "^4.1.1",
77
- "jsdom": "^29.1.1",
78
- "typescript": "^6.0.3",
79
- "vitest": "^3.2.1"
80
- },
81
- "volta": {
82
- "node": "24.0.0",
83
- "yarn": "4.12.0"
84
- }
85
- }
1
+ {
2
+ "name": "@sprlab/wccompiler",
3
+ "version": "0.14.0",
4
+ "description": "Zero-runtime compiler that transforms .wcc single-file components into native web components with signals-based reactivity",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": "./lib/compiler.js",
8
+ "./integrations/vue": "./integrations/vue.js",
9
+ "./integrations/react": "./integrations/react.js",
10
+ "./integrations/angular": "./integrations/angular.js",
11
+ "./adapters/vue": "./adapters/vue.js",
12
+ "./adapters/angular": {
13
+ "types": "./adapters/angular-compiled/angular.d.ts",
14
+ "default": "./adapters/angular-compiled/angular.mjs"
15
+ },
16
+ "./adapters/react": "./adapters/react.js"
17
+ },
18
+ "bin": {
19
+ "wcc": "./bin/wcc.js"
20
+ },
21
+ "files": [
22
+ "bin/",
23
+ "lib/*.js",
24
+ "!lib/*.test.js",
25
+ "integrations/",
26
+ "adapters/",
27
+ "types/",
28
+ "README.md"
29
+ ],
30
+ "types": "./types/wcc.d.ts",
31
+ "scripts": {
32
+ "test": "vitest --run",
33
+ "typecheck": "tsc --project jsconfig.json --noEmit"
34
+ },
35
+ "keywords": [
36
+ "web-components",
37
+ "compiler",
38
+ "custom-elements",
39
+ "zero-runtime",
40
+ "signals",
41
+ "native"
42
+ ],
43
+ "license": "MIT",
44
+ "publishConfig": {
45
+ "access": "public"
46
+ },
47
+ "dependencies": {
48
+ "@babel/generator": "^7.27.0",
49
+ "@babel/parser": "^7.27.0",
50
+ "@babel/traverse": "^7.27.0",
51
+ "@babel/types": "^7.27.0",
52
+ "esbuild": "^0.27.0",
53
+ "linkedom": "^0.18.12"
54
+ },
55
+ "peerDependencies": {
56
+ "@angular/core": ">=14.0.0",
57
+ "@vitejs/plugin-vue": ">=4.0.0",
58
+ "react": ">=18.0.0",
59
+ "vue": ">=3.0.0"
60
+ },
61
+ "peerDependenciesMeta": {
62
+ "@angular/core": {
63
+ "optional": true
64
+ },
65
+ "@vitejs/plugin-vue": {
66
+ "optional": true
67
+ },
68
+ "react": {
69
+ "optional": true
70
+ },
71
+ "vue": {
72
+ "optional": true
73
+ }
74
+ },
75
+ "devDependencies": {
76
+ "fast-check": "^4.1.1",
77
+ "jsdom": "^29.1.1",
78
+ "typescript": "^6.0.3",
79
+ "vitest": "^3.2.1"
80
+ },
81
+ "volta": {
82
+ "node": "24.0.0",
83
+ "yarn": "4.12.0"
84
+ }
85
+ }
package/types/wcc.d.ts CHANGED
@@ -1,28 +1,28 @@
1
- declare module 'wcc' {
2
- interface Signal<T> {
3
- (): T;
4
- set(value: T): void;
5
- }
6
-
7
- export function signal<T>(value: T): Signal<T>;
8
- export function computed<T>(fn: () => T): () => T;
9
- export function effect(fn: () => void): void;
10
- export function watch<T>(target: Signal<T>, fn: (newVal: T, oldVal: T) => void): void;
11
- export function watch<T>(target: () => T, fn: (newVal: T, oldVal: T) => void): void;
12
- export function defineComponent(options: {
13
- tag: string;
14
- }): void;
15
-
16
- export function defineProps<T extends Record<string, any>>(defaults: T): T;
17
- export function defineProps(names: string[]): Record<string, any>;
18
-
19
- export function defineEmits<T>(): T;
20
- export function defineEmits(names: string[]): (name: string, detail?: any) => void;
21
-
22
- export function templateRef<T = HTMLElement>(name: string): { value: T | null };
23
-
24
- export function onMount(fn: () => void | Promise<void>): void;
25
- export function onDestroy(fn: () => void | Promise<void>): void;
26
- export function onAdopt(fn: () => void | Promise<void>): void;
27
- export function defineExpose(bindings: Record<string, any>): void;
28
- }
1
+ declare module 'wcc' {
2
+ interface Signal<T> {
3
+ (): T;
4
+ set(value: T): void;
5
+ }
6
+
7
+ export function signal<T>(value: T): Signal<T>;
8
+ export function computed<T>(fn: () => T): () => T;
9
+ export function effect(fn: () => void): void;
10
+ export function watch<T>(target: Signal<T>, fn: (newVal: T, oldVal: T) => void): void;
11
+ export function watch<T>(target: () => T, fn: (newVal: T, oldVal: T) => void): void;
12
+ export function defineComponent(options: {
13
+ tag: string;
14
+ }): void;
15
+
16
+ export function defineProps<T extends Record<string, any>>(defaults: T): T;
17
+ export function defineProps(names: string[]): Record<string, any>;
18
+
19
+ export function defineEmits<T>(): T;
20
+ export function defineEmits(names: string[]): (name: string, detail?: any) => void;
21
+
22
+ export function templateRef<T = HTMLElement>(name: string): { value: T | null };
23
+
24
+ export function onMount(fn: () => void | Promise<void>): void;
25
+ export function onDestroy(fn: () => void | Promise<void>): void;
26
+ export function onAdopt(fn: () => void | Promise<void>): void;
27
+ export function defineExpose(bindings: Record<string, any>): void;
28
+ }
package/types/wcc.test.js CHANGED
@@ -1,46 +1,46 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { readFileSync, existsSync } from 'node:fs';
3
- import { resolve } from 'node:path';
4
- import { fileURLToPath } from 'node:url';
5
-
6
- const __dirname = fileURLToPath(new URL('.', import.meta.url));
7
- const dtsPath = resolve(__dirname, 'wcc.d.ts');
8
-
9
- describe('type declarations (wcc.d.ts)', () => {
10
- it('file exists', () => {
11
- expect(existsSync(dtsPath)).toBe(true);
12
- });
13
-
14
- it('contains signal declaration', () => {
15
- const content = readFileSync(dtsPath, 'utf-8');
16
- expect(content).toContain('function signal<T>(value: T): Signal<T>');
17
- });
18
-
19
- it('contains computed declaration', () => {
20
- const content = readFileSync(dtsPath, 'utf-8');
21
- expect(content).toContain('function computed<T>(fn: () => T): () => T');
22
- });
23
-
24
- it('contains effect declaration', () => {
25
- const content = readFileSync(dtsPath, 'utf-8');
26
- expect(content).toContain('function effect(fn: () => void): void');
27
- });
28
-
29
- it('contains defineComponent declaration', () => {
30
- const content = readFileSync(dtsPath, 'utf-8');
31
- expect(content).toContain('function defineComponent');
32
- expect(content).toContain('tag: string');
33
- expect(content).not.toContain('template?: string');
34
- expect(content).not.toContain('styles?: string');
35
- });
36
-
37
- it('Signal<T> interface has call signature (): T', () => {
38
- const content = readFileSync(dtsPath, 'utf-8');
39
- expect(content).toContain('(): T');
40
- });
41
-
42
- it('Signal<T> interface has set(value: T): void', () => {
43
- const content = readFileSync(dtsPath, 'utf-8');
44
- expect(content).toContain('set(value: T): void');
45
- });
46
- });
1
+ import { describe, it, expect } from 'vitest';
2
+ import { readFileSync, existsSync } from 'node:fs';
3
+ import { resolve } from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+
6
+ const __dirname = fileURLToPath(new URL('.', import.meta.url));
7
+ const dtsPath = resolve(__dirname, 'wcc.d.ts');
8
+
9
+ describe('type declarations (wcc.d.ts)', () => {
10
+ it('file exists', () => {
11
+ expect(existsSync(dtsPath)).toBe(true);
12
+ });
13
+
14
+ it('contains signal declaration', () => {
15
+ const content = readFileSync(dtsPath, 'utf-8');
16
+ expect(content).toContain('function signal<T>(value: T): Signal<T>');
17
+ });
18
+
19
+ it('contains computed declaration', () => {
20
+ const content = readFileSync(dtsPath, 'utf-8');
21
+ expect(content).toContain('function computed<T>(fn: () => T): () => T');
22
+ });
23
+
24
+ it('contains effect declaration', () => {
25
+ const content = readFileSync(dtsPath, 'utf-8');
26
+ expect(content).toContain('function effect(fn: () => void): void');
27
+ });
28
+
29
+ it('contains defineComponent declaration', () => {
30
+ const content = readFileSync(dtsPath, 'utf-8');
31
+ expect(content).toContain('function defineComponent');
32
+ expect(content).toContain('tag: string');
33
+ expect(content).not.toContain('template?: string');
34
+ expect(content).not.toContain('styles?: string');
35
+ });
36
+
37
+ it('Signal<T> interface has call signature (): T', () => {
38
+ const content = readFileSync(dtsPath, 'utf-8');
39
+ expect(content).toContain('(): T');
40
+ });
41
+
42
+ it('Signal<T> interface has set(value: T): void', () => {
43
+ const content = readFileSync(dtsPath, 'utf-8');
44
+ expect(content).toContain('set(value: T): void');
45
+ });
46
+ });