Giter VIP home page Giter VIP logo

swift-web-page-ui's Introduction

🧾 swift-web-page-ui (SwepUI)

Swift Version: 5.5 Swift Package Manager Swift Package Manager

SwepUI is an experimental project that intend to mimic SwiftUI functionality on the web using SwiftWasm. As of now it only has the reusability and encapsulation of the SwiftUI Views. But it missing a lot of features that SwiftUI has. For example: Modifiers, Layout, etc. However, you have full control over the css styling.

Table of Contents

Examples

A live example of SwepUI is available at Github Pages

import SwepUI

struct MyApp: App {
  var body: some Scene {
    WindowGroup {
      MyView()
        .display(.flex)
        .alignItems(.center)
        .justifyContent(.center)
        .height(.vh(100))
        .width(.vw(100))    
        .minWidth(100%)
        .minHeight(100%)
    }
  }
}

struct MyView: View {
  @State var counter: Int = 0
  @State var darkMode: Bool = false

  var body: some View {
    Div("counter = \(counter)")
      .color(darkMode ? .white : .tomato)
      .backgroundColor(darkMode ? .tomato : .white)
      .fontSize(.px(100))
      .fontFamily("Helvetica")
      .cursor(.pointer)
      .onClick { _ in
        counter += 1
        darkMode.toggle()
        print(counter)
      }
  }
}

// Run the webapp
MyApp.main()

Todo

  • Mimic SwiftUI Encapsulation
  • Being able to interact with the CSS style from outside its body as following: MyCustomView().backgroundColor(.red)
  • Mimic SwiftUI Modifiers
  • Mimic SwiftUI Layout

Requirements

In order to use SwepUI, you need to have the following:

  1. SwiftWasm installed
  2. Carton installed

NOTE: Installing Carton will also install SwiftWasm out of the box. Read more about the installation process here.

Getting Started

As mentioned earlier SwepUI require carton. You'll install carton via Homebrew. Assuming you already have Homebrew installed, you can create a new SwepUI app by following these steps:

  1. Install carton:
brew install swiftwasm/tap/carton

If you had carton installed before this, make sure you have version 0.16.0 or greater:

carton --version
  1. Create a directory for your project and make it current:
mkdir MySwepUIApp && cd MySwepUIApp
  1. Initialize the project from a template with carton:
carton init --template basic
  1. Add SwepUI as dependency package to your project:
dependencies: [
  .package(url: "https://github.com/alja7dali/swift-web-page-ui.git", from: "0.0.2")
]
  1. Add SwepUI as dependency target to MySwepUIApp:
targets: [
  .target(
    name: "MySwepUIApp",
    dependencies: [
      .product(name: "SwepUI", package: "swift-web-page-ui"),
    ]
  ),
]
  1. Build the project and start the development server, carton dev can be kept running during development:
carton dev
  1. Open http://127.0.0.1:8080/ in your browser to see the app running. You can edit the app source code in your favorite editor and save it, carton will immediately rebuild the app and reload all browser tabs that have the app open.

  2. After you are done with the development, you can bundle the app for production use by running:

carton bundle

NOTE: You can also clone this repository and run carton dev --product SwepUIExample in its root directory. This will build the demo app that shows almost all of the currently implemented APIs. Or check out the live example based on SwepUIExample is available at Github Pages

Note

Special thanks to the team and contributors behind SwiftWasm & Carton ♥️..

License

All modules are released under the MIT license. See LICENSE for details.

swift-web-page-ui's People

Contributors

alja7dali avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.