css3transform
npm i css3transform

css3transform

Front End Cross-Frameworks Framework - 前端跨框架框架

by Tencent

1.2.3 (see all)License:MITTypeScript:Not Found
npm i css3transform
Readme

English | 简体中文

omi

Omi - Front End Cross-Frameworks Framework

Omiu - Cross-Frameworks and Cross-Themes UI Components powered by Omi

Define cross-frameworks button element with typescript:

import { tag, WeElement, h, extractClass } from 'omi'
import * as css from './index.scss'

interface Props {
  size?: 'medium' | 'small' | 'mini',
  type?: 'primary' | 'success' | 'warning' | 'danger' | 'info' | 'text'
  plain?: boolean,
  round?: boolean,
  circle?: boolean,
  loading?: boolean,
  disabled?: boolean,
  icon?: string,
  autofocus?: boolean,
  nativeType?: 'button' | 'submit' | 'reset',
  block?: boolean
  text?: string
}

@tag('o-button')
export default class Button extends WeElement<Props>{
  static css = css

  static defaultProps = {
    plain: false,
    round: false,
    circle: false,
    loading: false,
    disabled: false,
    autofocus: false,
    nativeType: 'button',
    block: false
  }

  static propTypes = {
    size: String,
    type: String,
    plain: Boolean,
    round: Boolean,
    circle: Boolean,
    loading: Boolean,
    disabled: Boolean,
    icon: String,
    autofocus: Boolean,
    nativeType: String,
    block: Boolean,
    text: String
  }

  render(props) {
    return <button disabled={props.disabled} {...extractClass(props, 'o-button', {
      ['o-button-' + props.type]: props.type,
      ['o-button-' + props.size]: props.size,
      'is-plain': props.plain,
      'is-round': props.round,
      'is-circle': props.circle,
      'is-disabled': props.disabled,
      'is-block': props.block
    })} type={props.nativeType} >
      {props.loading && <i class='icon-loading'></i>}
      {props.text}
      <slot></slot>
    </button>
  }
}

New Project by Omi

$ npm i omi-cli -g    # install cli
$ omi init my-app     # init project
$ cd my-app           
$ npm start           # develop
$ npm run build       # release

npx omi-cli init my-app is also supported(npm v5.2.0+).

New Component by Omi

$ npm i omi-cli -g    # install cli
$ omi init-component my-component     # init project
$ cd my-app           
$ npm start           # develop
$ npm run build       # release

npx omi-cli init-component my-component is also supported(npm v5.2.0+).

Ecosystem of Omi

💯Base

ProjectDescription
omi-docs and codepenOmi official documents
omi-routerOmi official router in 1KB js
omi-cliProject scaffolding. → Base Templates
CEEFork from custom-elements-everywhere

🐍Snake MVP

ProjectDescription
omi-snake & → Touch the demoThe Snake-Eating Game Based on MVP Architecture Written by Omi
omi-kbone-snake omi-kbone 写的 MVP 架构的跨端贪吃蛇游戏,支持小程序和 H5
Preact-snakeThe Snake-Eating Game Based on MVP Architecture Written by Preact + Preact-CSS + Omis
[P]react-snakeThe Snake-Eating Game Based on MVP Architecture Written by React/Preact
omix-snake小程序贪吃蛇

📚Other

ProjectDescription
omi-pianoBuild piano with Omi and Omi Snippets, Enjoy now!
omi-devtoolsBrowser DevTools extension
omi-chartSimple HTML5 Charts using chart-x tag.
md2siteStatic Site Generator with markdown powered by Omio.
omi-30-secondsUseful Omi snippets that you can understand in 30 seconds.
omi-canvasPerfect fusion of web components, jsx and canvas.
omi-swiperOmi + Swiper
omi-vscodeVSCode extension for omi, Install now!
omi-exOmi.js extension(TypeScript)
omi-transformOmi / css3transform integration. Made css3 transform super easy in your Omi project.
omi-fingerSupport touch and gesture events in your Omi project.
omi-touchSmooth scrolling, rotation, pull to refresh and any motion for the web.
omi-nativeRender web components to native
omi-i18nInternationalization solution for omi.js using i18next ecosystem
omieBuild cross platform desktop apps with Omi.js and Electron.js
omi-cvCreate a front-end engineer curriculum vitae, Get Started!
SooHas same API as omi but is great alternative if you want to create custom elements without JSX, virtual DOM and store

Why Omi?

  • Tiny size and High performance
  • Cross frameworks(react, preact, vue, angular), components of omi are pure custom elements
  • One framework. Mobile & desktop & mini program
  • Stateless View Architecture Design
  • Be friendly to custom elements, you can pass false attributes to elements through string '0' or string 'false', you can pass object attributes to elements through : prefix and Omi.$
  • Easy two way binding by extend api
  • Enhanced CSS, rpx unit support base on 750 screen width
  • Compliance with browser trend and API design
  • Merge Web Components, JSX into one framework
  • Web Components can also be a data-driven view, UI = fn(data).
  • JSX is the best development experience (code intelligent completion and tip) UI Expression with least grammatical noise and it's turing complete(template engine is not, es template string is but grammatical noise is too loud)
  • Look at Facebook React vs Web Components,Omi combines their advantages and gives developers the freedom to choose the way they like
  • Shadow DOM or Light DOM merges with Virtual DOM, Omi uses both virtual DOM and real Shadow DOM to make view updates more accurate and faster
  • Scoped CSS's best solution is Shadow DOM, the community churning out frameworks and libraries for Scoped CSS (using JS or JSON writing styles such as Radium, jsxstyle, react-style; binding to webpack using generated unique className filename-classname-hash, such as CSS Modules, Vue), are hack technologies; and Shadow DOM Style is the perfect solution.

Compare TodoApp by Omi and React, Omi and React rendering DOM structure:

OmiReact
OmiReact

Omi uses Shadow DOM or Light DOM based style isolation and semantic structure.

Useful Resources

Title NameOther languageRelated
Web Components bookmarks
Snake-Eating Game Making with Web Components of Omi and MVP Architecture
Constructable Stylesheets: seamless reusable styles
Web Components specifications
Web Components in a Nutshell
Using Web Components with React in 2019
Using Web Components in React
Styling We Components Using A Shared Style Sheet
Developer Tools support for Web Components in Firefox 63
Develop W3C Web Components with WebAssembly
60FPS Animation In Omi简体中文 한국어
Render Web Components To Native简体中文 한국어
Shadow Dom In Depth简体中文
Part Theme Explainer求翻译
Web Components MDN简体中文
Web Components Google
Web Components Org
Web Components: the Right Way
Proxy MDN简体中文 한국어
CSS Variables简体中文 한국어
CSS Shadow Parts
Platform HTML5
Using requestIdleCallback简体中文A polyfill
The Power Of Web Components简体中文
ShadowRoot简体中文

Overview of the Readme

Getting Started

Project Template

Template TypeCommandDescribe
Base Templateomi init my-appBasic omi project template.
Kbone Templateomi init-kbone my-appDeveloping mini program or web using omi.

Hello Element

Define a custom element by extending WeElement base class:

import { define, WeElement } from 'omi'

define('hello-element', class extends WeElement {
  onClick = evt => {
    // trigger CustomEvent
    this.fire('Abc', { name: 'dntzhang', age: 12 })
    evt.stopPropagation()
  }

  //If you need to use <hello-element></hello-element> directly in html, you must declare propTypes
  static propTypes = {
    msg: String
  }

  static css = `
      div {
        color: red;
        cursor: pointer;
      }`

  render(props) {
    return (
      <div onClick={this.onClick}>
        Hello {props.msg}
        <div>Click Me!</div>
      </div>
    )
  }
})

Using hello-element:

import { define, render, WeElement } from 'omi'
import './hello-element'

define('my-app', class extends WeElement {
  data = { abc: 'abc' }

  // define CustomEvent Handler
  onAbc = evt => {
    // get evt data by evt.detail
    this.data.abc = ' by ' + evt.detail.name
    this.update()
  }

  static css = `
      div{
          color: green;
      }`

  render(props) {
    return (
      <div>
        Hello {this.data.abc}
        <hello-element
          onAbc={this.onAbc}
          msg="WeElement"
        />
      </div>
    )
  }
})

render(<my-app name="Omi v4.0" />, 'body')

Tell Babel to transform JSX into Omi.h() call:

{
  "presets": ["env", "omi"]
}

The following two NPM packages need to be installed to support the above configuration:

"babel-preset-env": "^1.6.0",
"babel-preset-omi": "^0.1.1",

If you use babel7, you can also use the following packages and configuration:

npm install --save-dev @babel/preset-env
npm install --save-dev @babel/preset-react
{
  "presets": [
    "@babel/preset-env",
    [
      "@babel/preset-react",
      {
        "pragma": "Omi.h",
        "pragmaFrag": "Omi.h.f"
      }
    ]
  ]
}

If you don't want to write CSS in JS, you can use to-string-loader of webpack. For example, the following configuration:

{
  test: /[\\|\/]_[\S]*\.css$/,
  use: [
    'to-string-loader',
    'css-loader'
  ]
}

If your CSS file starts with "_", CSS will use to-string-loader, such as:

import { tag, WeElement render } from 'omi'

define('my-app', class extends WeElement {

  css = require('./_index.css')
  ...
  ...
  ...

You can also forget the tedious configuration and use omi-cli directly, no need to configure anything.

TypeScript Auto Complete

import { h, WeElement, tag, classNames } from 'omi';
import * as styles from './_index.less';

interface ButtonProps {
  href?: string,
  disabled?: boolean,
  type?: 'default' | 'primary' | 'danger',
  htmltype?: 'submit' | 'button' | 'reset',
  onClick?: (e: any) => void
}

const TAG = 'o-button'

declare global {
  namespace JSX {
    interface IntrinsicElements {
      [TAG]: Omi.Props & ButtonProps
    }
  }
}

@tag(TAG)
export default class oButton extends WeElement<ButtonProps> {
...
...
...
omi

Lifecycle

Lifecycle methodWhen it gets called
installbefore the component gets mounted to the DOM
installedafter the component gets mounted to the DOM
uninstallprior to removal from the DOM
beforeUpdatebefore update
updatedafter update
beforeRenderbefore render()
receivePropsparent element re-render will trigger it, return false will prevent update action

View registered elements

console.log(Omi.elements)

Browsers Support

Omi works in the latest two versions of all major browsers: Safari 10+, IE 11+, and the evergreen Chrome, Firefox, and Edge.

→ Browsers Support

→ Polyfills

<script src="https://unpkg.com/@webcomponents/webcomponentsjs@2.0.0/webcomponents-bundle.js"></script>

Contribution

Build a example:

npm start example_name

Build omi:

npm run build

Unit testing

npm run test

Contributors

Any form of contribution is welcome. The above contributors have been officially released by Tencent.

We very much welcome developers to contribute to Tencent's open source, and we will also give them incentives to acknowledge and thank them. Here we provide an official description of Tencent's open source contribution. Specific contribution rules for each project are formulated by the project team. Developers can choose the appropriate project and participate according to the corresponding rules. The Tencent Project Management Committee will report regularly to qualified contributors and awards will be issued by the official contact.

Core Maintainers

Please contact us for any questions.

Thanks

License

MIT © Tencent

Downloads/wk

171

GitHub Stars

12.3K

LAST COMMIT

6mos ago

MAINTAINERS

1

CONTRIBUTORS

98

OPEN ISSUES

93

OPEN PRs

0
VersionTagPublished
1.2.3
latest
3yrs ago
No alternatives found
No tutorials found
Add a tutorial