# tzer

> Web Components Micro Framework

Latest version **1.0.45** (published 2022-10-25) · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install tzer
pnpm add tzer
yarn add tzer
bun add tzer
```

Provides the command `tzer`.

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.45 |
| Published | 2022-10-25 |
| First published | 2022-10-18 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 10 |
| Unpacked size | 42.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Dror Seltzer |
| Maintainers | drorsel |

## Links

- npm: https://www.npmjs.com/package/tzer
- Repository: https://github.com/drorseltzer/tzer
- Homepage: https://github.com/drorseltzer/tzer#readme
- Issues: https://github.com/drorseltzer/tzer/issues
- npm.io page: https://npm.io/package/tzer

## Dependencies (10)

- [sass](https://npm.io/package/sass.md) ^1.55.0
- [yargs](https://npm.io/package/yargs.md) ^17.6.0
- [terser](https://npm.io/package/terser.md) ^5.15.1
- [ts-node](https://npm.io/package/ts-node.md) ^10.9.1
- [prettier](https://npm.io/package/prettier.md) ^2.7.1
- [@swc/core](https://npm.io/package/@swc/core.md) ^1.3.10
- [@swc/helpers](https://npm.io/package/@swc/helpers.md) ^0.4.12
- [@types/yargs](https://npm.io/package/@types/yargs.md) ^17.0.13
- [@types/prettier](https://npm.io/package/@types/prettier.md) ^2.7.1
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.13

## Recent versions

- 1.0.45 (latest) — 2022-10-25
- 1.0.44 — 2022-10-25
- 1.0.43 — 2022-10-25
- 1.0.42 — 2022-10-24
- 1.0.41 — 2022-10-23
- 1.0.40 — 2022-10-23
- 1.0.39 — 2022-10-23
- 1.0.38 — 2022-10-23
- 1.0.37 — 2022-10-23
- 1.0.36 — 2022-10-22
- 1.0.35 — 2022-10-22
- 1.0.34 — 2022-10-22
- 1.0.33 — 2022-10-22
- 1.0.31 — 2022-10-21
- 1.0.30 — 2022-10-21
- … 23 more at https://npm.io/package/tzer/versions

## README

# TZer - Web Components Micro Framework 
## ************************** WIP **************************

[![Node.js CI](https://github.com/drorseltzer/tzer/actions/workflows/node.js.yml/badge.svg)](https://github.com/drorseltzer/tzer/actions/workflows/node.js.yml)

### Purpose
WC is not the most dev-friendly API, but still I ran into cases I need a custom WC without using a framework.

### How It Works
TZer rely on decorators declaration to compile the component into a JS CustomElement Class and then bundle all using esbuild.

### Features
 - 100% native vanilla js code - no libraries!
 - Manging attribute easily - with observed attributes.
 - Event binding.
 - Supporting all WC lifecycles - added multiple callbacks.
 - SCSS/SASS.
 - Minifying & Optimizing.
 - No Shadow Dom - partially encapsulated.
 - Supporting imports - from `utils` folder - WIP
 - Seed project generator from cli.
 
### Install
```shell
npm i -g tzer
npx tzer init newProject
cd newProject
npm i
npm run dev
```

### Compiling
Run `npx tzer compile`.

### Importing
Import like any other js file.

### Config
```typescript
// tzer.config.ts

import { ExampleComponent } from "./example/component";

export default {
  components: [ExampleComponent]
}
```

### CLI
 - `tzer init PROJECT_NAME` - create a new TZer project.
 - `tzer generate COMPONENT_NAME` - create a new component.

### Project NPM Commands
 - `dev` run a dev server, watch & environment
 - `build` build final output
 - `tzer:build:debug` build debuggable output before bundling and renaming
 - `tzer:build:dev` build debuggable output after bundling and renaming

### Decorators

##### @TzerComponent({componentElementTag: string, style: string, domHelpers?: boolean})
Main declaration of a component.

##### @TzerAttribute({observed?: boolean})
Create an element attribute, with getter and setter.

Attribute can set to observed to invoke the `attributeChangedCallback(optional)`.

##### @TzerAttributeChangedCallback(attribute?: string)
Trigger whenever an observed attribute has changed.

`attribute(optional)` the callback will run only for that attribute change, otherwise for all changes.

##### @TzerConnectedCallback()
Trigger whenever the component has mounted in the document.

##### @TzerDisconnectedCallback()
Trigger whenever the component has dismounted from the document.

##### @TzerAdoptedCallback()
Trigger whenever the component has moved to a new document.

##### @TzerEventBind(eventName: string)
Binds a method to a custom event.

### Example Component
```typescript
// component.ts

import {
  TzerAdoptedCallback,
  TzerAttribute,
  TzerAttributeChangedCallback,
  TzerComponent,
  TzerConnectedCallback,
  TzerDisconnectedCallback, TzerEventBind
} from "tzer";

@TzerComponent({ 
  componentElementTag: 'tzer-example-component',
  style: './src/example/example.scss'
})
export class Example {
  declare container: HTMLElement;
  declare DOM: TzerDOM;

  @TzerAttribute({ observed: true })
  testattr: string | undefined;

  @TzerConnectedCallback()
  connected() {
    console.log('connected!');
  }

  @TzerDisconnectedCallback()
  disconnected() {
    console.log('disconnected!');
  }

  @TzerAdoptedCallback()
  adopted() {
    console.log('adopted!');
  }

  @TzerEventBind('click')
  eventListener() {
    console.log('clicked!');
  }

  @TzerConnectedCallback()
  @TzerAttributeChangedCallback()
  render() {
    this.container.innerHTML = `<p>Hello ${this.testattr}!</p>`;
  }
}
```

---
_Source: https://npm.io/package/tzer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
