regor 1.3.5 → 1.3.7

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 CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  # Regor
4
4
 
5
- Regor is a powerful UI framework designed to streamline the development of HTML5-based applications for both web and desktop environments. With a template syntax that closely follows Vue.js, transitioning from VueJS to Regor is seamless for developers familiar with Vue.
5
+ Regor is a runtime-first UI framework for teams that want direct DOM control, strong TypeScript ergonomics, and precise reactivity behavior without being forced into a Virtual DOM architecture.
6
+
7
+ Its template syntax is familiar to Vue users (`r-if`, `r-model`, `r-for`, `r-bind`), but its runtime model is intentionally different: Regor is built for progressive enhancement, mixed-rendering environments, and incremental adoption.
6
8
 
7
9
  ### [![Published on npm](https://img.shields.io/npm/v/regor.svg)](https://www.npmjs.com/package/regor)
8
10
 
@@ -10,9 +12,9 @@ Regor is a powerful UI framework designed to streamline the development of HTML5
10
12
 
11
13
  ## Key Features
12
14
 
13
- - **Simplicity:** Develop UIs without a Virtual DOM for a more straightforward implementation and easier debugging.
14
- - **TypeScript:** Enjoy native TypeScript support without workarounds.
15
- - **No Build Step Required:** Define components in TypeScript using tagged string templates, no build step needed.
15
+ - **No VDOM Layer:** Bind directly to real DOM for transparent runtime behavior and straightforward debugging.
16
+ - **TypeScript-Native:** Use standard TypeScript interfaces, classes, and generics without framework-specific file formats.
17
+ - **No Build Step Required:** Define components in TypeScript using tagged string templates with npm, CDN ESM, or global build workflows.
16
18
  - **Secure Evaluation:** Regor's secure JavaScript VM ensures safe runtime compilation. You can enable security policy in your page without removing runtime compilation support.
17
19
 
18
20
  ```html
@@ -22,9 +24,9 @@ Regor is a powerful UI framework designed to streamline the development of HTML5
22
24
  />
23
25
  ```
24
26
 
25
- - **Flexible Reactivity:** Empowering developers with a highly flexible reactivity system.
26
- - **Non-JS SSR:** Bind to the existing DOM without removing already mounted HTML elements, suitable for non-JavaScript server-side rendering.
27
- - **Reentrance:** Regor supports multiple mountings in the previously mounted area using the same or different app contexts. This enables creating and mounting new directives dynamically.
27
+ - **Flexible Reactivity:** Combine `ref`, `sref`, `batch`, `pause`, `resume`, and `entangle` for explicit state orchestration.
28
+ - **Static-First + Islands:** Bind to existing DOM without removing server-rendered HTML, ideal for progressive enhancement.
29
+ - **Reentrance:** Mount multiple times in already-mounted regions with same or different app contexts.
28
30
  - **Compatibility:** Rendered pages are designed for seamless integration with other libraries manipulating the DOM.
29
31
 
30
32
  ## Documentation
@@ -60,7 +62,7 @@ HTML:
60
62
  Defining component:
61
63
 
62
64
  ```ts
63
- import { createApp, createComponent, ref, html, type Ref } from 'regor'
65
+ import { createApp, defineComponent, ref, html, type Ref } from 'regor'
64
66
 
65
67
  interface MyComponent {
66
68
  message: Ref<string>
@@ -72,16 +74,13 @@ const template = html`<button @click="count++">
72
74
 
73
75
  const props = ['message']
74
76
 
75
- const myComponent = createComponent<MyComponent>(
76
- template,
77
- {
78
- context: (head) => ({
79
- message: head.props.message,
80
- count: ref(0),
81
- }),
82
- props,
83
- },
84
- )
77
+ const myComponent = defineComponent<MyComponent>(template, {
78
+ context: (head) => ({
79
+ message: head.props.message,
80
+ count: ref(0),
81
+ }),
82
+ props,
83
+ })
85
84
 
86
85
  createApp({
87
86
  components: { myComponent },
@@ -121,7 +120,7 @@ Example:
121
120
  ```
122
121
 
123
122
  ```ts
124
- const tableRow = createComponent(
123
+ const tableRow = defineComponent(
125
124
  html`<tr>
126
125
  <TableCell :value="row.name" />
127
126
  <TableCell :value="row.age" />
@@ -161,7 +160,31 @@ or
161
160
 
162
161
  ## Comparison with VueJs
163
162
 
164
- Regor shares core functionality with VueJs but differs in implementation, TypeScript support, template evaluation, reactivity, server-side rendering support, compatibility.
163
+ Regor is openly inspired by Vue’s concepts (even adopting a similar directive syntax like r-if / r-model instead of v-if / v-model), but it fundamentally diverges in its implementation. It prioritizes runtime flexibility, build-less environments, and strict TypeScript integration over the Virtual DOM (VDOM) paradigm.
164
+
165
+ ### Architecture and rendering model
166
+
167
+ - **Vue:** Uses a Virtual DOM. This provides excellent performance for highly dynamic Single Page Applications (SPAs) because Vue calculates diffs in memory before updating the browser. However, it usually requires a compilation step to optimize templates, and hydrating existing server-rendered HTML can be notoriously strict (hydration mismatches).
168
+ - **Regor:** Ditches the VDOM entirely. It binds directly to the actual DOM. Regor explicitly supports Static-first + dynamic islands and "Reentrance." You can mount an application multiple times over already-mounted regions or existing server-rendered HTML without destroying the elements.
169
+ - **Verdict:** Regor is significantly more flexible for integrating into existing applications, multi-page applications (MPAs), or legacy backends.
170
+
171
+ ### Runtime and deployment model
172
+
173
+ - **Vue:** Commonly paired with a build pipeline for SFCs and tooling depth.
174
+ - **Regor:** Designed to require no build step. You can write standard TypeScript using tagged string templates (e.g., `html` tags for templates) and it will evaluate at runtime. Crucially, Regor features a Secure JavaScript VM for runtime compilation that adheres to strict Content Security Policies (CSP)—a common pain point when using Vue's runtime compiler in enterprise environments.
175
+ - **Verdict:** Regor wins in deployment flexibility and zero-config setups. It respects modern security policies out of the box without demanding a bundler.
176
+
177
+ ### Reactivity control model
178
+
179
+ - **Vue:** Uses ES6 Proxies for a highly automated, "magical" reactivity system. You update an object, and Vue figures out what to re-render. However, this magic can sometimes abstract away performance bottlenecks, leading to over-rendering if you aren't careful with deep reactivity.
180
+ - **Regor:** Provides fine-tuned, manual control. It offers `ref` (deep reactivity) and `sref` (simple/shallow reactivity without nested observation). Furthermore, Regor provides advanced control APIs like `pause()` and `resume()` to stop a ref's auto-triggers, `entangle()` to sync two refs effortlessly, and `batch()` for precise state grouping.
181
+ - **Verdict:** Vue's reactivity is easier for beginners.. Regor’s reactivity is more flexible and transparent, giving engineers exact tools to orchestrate update semantics and prevent unwanted DOM paints.
182
+
183
+ ### TypeScript ergonomics
184
+
185
+ - **Vue:** TypeScript support in Vue has improved massively, but it still relies on heavy IDE plugins (Volar) and specialized compilers (vue-tsc) to understand .vue files. The separation between the `<template>` and `<script>` requires tooling to bridge the gap.
186
+ - **Regor:** Offers native TypeScript support without workarounds. Because components and templates are defined using standard TypeScript functions, class-based contexts, and `ComponentHead<T>`, standard TypeScript compilers and IDEs understand 100% of the code immediately.
187
+ - **Verdict:** Regor offers a purer, higher-quality TypeScript experience. It leverages the language itself rather than relying on framework-specific compiler magic to provide type safety.
165
188
 
166
189
  ## Supported Directives
167
190
 
@@ -199,7 +222,7 @@ These directives empower you to create dynamic and interactive user interfaces,
199
222
  **App / Component Template Functions**
200
223
 
201
224
  - **`createApp`** Similar to Vue's `createApp`, it initializes a Regor application instance.
202
- - **`createComponent`** Creates a Regor component instance.
225
+ - **`defineComponent`** Creates a Regor component instance.
203
226
  - **`toFragment`** Converts a JSON template to a document fragment.
204
227
  - **`toJsonTemplate`** Converts a DOM element to a JSON template.
205
228
 
package/dist/regor.d.ts CHANGED
@@ -11,8 +11,9 @@
11
11
  *
12
12
  * Typical usage:
13
13
  * ```ts
14
- * const Card = createComponent({
15
- * template: `<article><h3 r-text="title"></h3></article>`,
14
+ * const Card = defineComponent(
15
+ * `<article><h3 r-text="title"></h3></article>`,
16
+ * {
16
17
  * props: ['title'],
17
18
  * context(head) {
18
19
  * // read parent values
@@ -188,17 +189,34 @@ export declare interface IRegorContext extends Record<string, unknown> {
188
189
  }
189
190
  export type IsLazy = (i: number, d: number) => boolean;
190
191
  export type IsLazyKey = (key: string, d: number) => boolean;
192
+ export interface DirectiveUpdatePayload {
193
+ el: HTMLElement;
194
+ expr: string;
195
+ values: unknown[];
196
+ previousValues?: unknown[];
197
+ option?: unknown;
198
+ previousOption?: unknown;
199
+ flags?: string[];
200
+ parseResult: ParseResult;
201
+ dynamicOption?: ParseResult;
202
+ }
203
+ export interface MountedDirective {
204
+ update?: (payload: DirectiveUpdatePayload) => void;
205
+ unmount?: Unbinder;
206
+ }
191
207
  export interface Directive {
192
208
  isLazy?: IsLazy;
193
209
  isLazyKey?: IsLazyKey;
194
210
  collectRefObj?: boolean;
195
- /** if once is enabled, the onChange is never triggered.
196
- * The refs in parseResult are still reactive. */
211
+ /** If once is enabled, updates are not re-triggered after initial mount. */
197
212
  once?: boolean;
198
- /** Called on every value change. */
199
- onChange?: (el: HTMLElement, values: unknown[], previousValues?: unknown[], option?: unknown, previousOption?: unknown, flags?: string[]) => void;
200
- /** Called on binding. Returns unbinder. */
201
- onBind?: (el: HTMLElement, parseResult: ParseResult, expr: string, option?: string, dynamicOption?: ParseResult, flags?: string[]) => Unbinder;
213
+ /**
214
+ * Called once at bind time.
215
+ * Returns either:
216
+ * - unmount function
217
+ * - mounted object with `update` and/or `unmount`
218
+ */
219
+ mount: (payload: DirectiveUpdatePayload) => Unbinder | MountedDirective | void;
202
220
  }
203
221
  export interface BindData {
204
222
  unbinders: Unbinder[];
@@ -206,9 +224,9 @@ export interface BindData {
206
224
  }
207
225
  export type Unbinder = () => void;
208
226
  export interface ParseResult {
209
- value: SRef<unknown[]>;
227
+ value: () => unknown[];
210
228
  stop: StopObserving;
211
- subscribe?: (observer: ObserveCallback<unknown[]>, init?: boolean) => StopObserving;
229
+ subscribe: (observer: ObserveCallback<unknown[]>, init?: boolean) => StopObserving;
212
230
  refs: Array<AnyRef | undefined>;
213
231
  context: Record<string, unknown>;
214
232
  }
@@ -231,36 +249,36 @@ export interface JSONTemplate {
231
249
  * - Define either 'selector' or 'element' to specify the mounting point.
232
250
  * - Optionally, 'html' or 'json' can be defined to override the inner HTML of the mounting point.
233
251
  * - If neither 'html' nor 'json' template is defined, the mounting point's inner HTML remains unchanged.
234
- * If used with 'createComponent':
252
+ * If used with 'defineComponent':
235
253
  * - Define only one option: 'selector', 'element', 'html', or 'json'. The single option defines the component's HTML template.
236
254
  */
237
255
  export interface Template {
238
256
  /**
239
257
  * If used with 'createApp', specifies the target root element for mounting the application.
240
- * If used with 'createComponent', identifies the component template using a selector.
258
+ * If used with 'defineComponent', identifies the component template using a selector.
241
259
  */
242
260
  selector?: string;
243
261
  /**
244
262
  * If used with 'createApp', represents the actual DOM element where the app will be mounted.
245
- * If used with 'createComponent', specifies the component template using an element.
263
+ * If used with 'defineComponent', specifies the component template using an element.
246
264
  * Use this property if you already have a reference to the target element.
247
265
  */
248
266
  element?: Node;
249
267
  /**
250
268
  * If used with 'createApp', HTML template string that will replace the content of the root element defined by 'selector' or 'element'.
251
- * If used with 'createComponent', this template populates the content of the component.
269
+ * If used with 'defineComponent', this template populates the content of the component.
252
270
  */
253
271
  template?: string;
254
272
  /**
255
273
  * JSON-based template representation, enabling rendering within secure contexts.
256
274
  * Can be a single JSONTemplate object or an array of JSONTemplate objects.
257
- * This property is applicable to both 'createApp' and 'createComponent'.
275
+ * This property is applicable to both 'createApp' and 'defineComponent'.
258
276
  */
259
277
  json?: JSONTemplate | JSONTemplate[];
260
278
  /**
261
279
  * Indicates whether the component template contains SVG elements.
262
280
  * Enable this flag if SVG content is present to ensure proper rendering.
263
- * This property is applicable to both 'createApp' and 'createComponent'.
281
+ * This property is applicable to both 'createApp' and 'defineComponent'.
264
282
  */
265
283
  isSVG?: boolean;
266
284
  }
@@ -302,7 +320,7 @@ export interface Component<TContext extends IRegorContext | object = IRegorConte
302
320
  }
303
321
  export type OnMounted = () => void;
304
322
  export type OnUnmounted = () => void;
305
- export interface CreateComponentOptions<TContext extends IRegorContext | object = IRegorContext> {
323
+ export interface DefineComponentOptions<TContext extends IRegorContext | object = IRegorContext> {
306
324
  /**
307
325
  * Enables interpolation transform inside the component template.
308
326
  *
@@ -369,7 +387,7 @@ export interface CreateComponentOptions<TContext extends IRegorContext | object
369
387
  *
370
388
  * Example:
371
389
  * ```ts
372
- * const Card = createComponent('<div>...</div>', { defaultName: 'CardView' })
390
+ * const Card = defineComponent('<div>...</div>', { defaultName: 'CardView' })
373
391
  * cfg.addComponent(Card)
374
392
  * // usable as <CardView></CardView>
375
393
  * ```
@@ -423,21 +441,21 @@ export declare const createApp: <TRegorContext extends IRegorContext | object =
423
441
  /**
424
442
  * Creates a reusable Regor component definition.
425
443
  *
426
- * `createComponent` prepares a template once, then Regor clones/binds it for each
444
+ * `defineComponent` prepares a template once, then Regor clones/binds it for each
427
445
  * component instance in the app.
428
446
  *
429
447
  * @typeParam TContext - Component context type.
430
- * @param template Component template source:
448
+ * @param template - Component template source:
431
449
  * - inline HTML string
432
450
  * - `Template` object (`template`, `element`, `selector`, or `json`)
433
- * @param options Component options (`context`, `props`, `inheritAttrs`, etc.).
451
+ * @param options - Component options (`context`, `props`, `inheritAttrs`, etc.).
434
452
  * You can also pass `string[]` as shorthand for `props`.
435
453
  *
436
454
  * @returns Component definition usable in app/component `components`.
437
455
  *
438
456
  * @example
439
457
  * ```ts
440
- * const UserCard = createComponent(
458
+ * const UserCard = defineComponent(
441
459
  * `<article><h3 r-text="name"></h3></article>`,
442
460
  * {
443
461
  * props: ['name'],
@@ -451,13 +469,13 @@ export declare const createApp: <TRegorContext extends IRegorContext | object =
451
469
  * @example
452
470
  * ```ts
453
471
  * // Props shorthand:
454
- * const CounterLabel = createComponent(
472
+ * const CounterLabel = defineComponent(
455
473
  * `<span r-text="value"></span>`,
456
474
  * ['value'],
457
475
  * )
458
476
  * ```
459
477
  */
460
- export declare const createComponent: <TContext extends IRegorContext | object = IRegorContext>(template: Template | string, options?: CreateComponentOptions<TContext> | string[]) => Component<TContext>;
478
+ export declare const defineComponent: <TContext extends IRegorContext | object = IRegorContext>(template: Template | string, options?: DefineComponentOptions<TContext> | string[]) => Component<TContext>;
461
479
  export declare const toFragment: (json: JSONTemplate | JSONTemplate[], isSVG?: boolean, config?: RegorConfig) => DocumentFragment;
462
480
  export declare const toJsonTemplate: (node: Element | Element[]) => JSONTemplate | JSONTemplate[];
463
481
  export declare const addUnbinder: (node: Node, unbinder: Unbinder) => void;