Consolidate Lit repositories: figma-to-lit, figma_lit_example, lit-3d-piano, lit-calculator, lit-code-editor, lit-draggable-dom, lit-file-based-routing, lit-force-graph, lit-html-editor, lit-html-table, lit-modules, lit-native, lit-node-editor, lit-sheet-music, lit-starter-ts, lit-vscode-extension, lit-wmr, vite-lit-capacitor, vite-lit-element-starter, vite-rxdb-lit

This commit is contained in:
2026-05-16 22:17:12 -07:00
parent 4dc3c8a3ff
commit 95667e3038
527 changed files with 63872 additions and 54 deletions
@@ -0,0 +1,359 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objects = {
/* Begin PBXBuildFile section */
F7BF721F267F0F0A00CE9E58 /* App.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7BF721E267F0F0A00CE9E58 /* App.swift */; };
F7BF7221267F0F0A00CE9E58 /* Screen.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7BF7220267F0F0A00CE9E58 /* Screen.swift */; };
F7BF7223267F0F0C00CE9E58 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F7BF7222267F0F0C00CE9E58 /* Assets.xcassets */; };
F7BF7226267F0F0C00CE9E58 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F7BF7225267F0F0C00CE9E58 /* Preview Assets.xcassets */; };
F7BF7237267F243D00CE9E58 /* build in Resources */ = {isa = PBXBuildFile; fileRef = F7BF7236267F243D00CE9E58 /* build */; };
F7BF723A267F247500CE9E58 /* Bundle.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7BF7239267F247500CE9E58 /* Bundle.swift */; };
F7BF723D267F248200CE9E58 /* Events.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7BF723C267F248200CE9E58 /* Events.swift */; };
F7BF7240267F248E00CE9E58 /* State.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7BF723F267F248E00CE9E58 /* State.swift */; };
F7BF7243267F24A500CE9E58 /* WebView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7BF7242267F24A500CE9E58 /* WebView.swift */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
F7BF721B267F0F0A00CE9E58 /* ios.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ios.app; sourceTree = BUILT_PRODUCTS_DIR; };
F7BF721E267F0F0A00CE9E58 /* App.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = App.swift; sourceTree = "<group>"; };
F7BF7220267F0F0A00CE9E58 /* Screen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Screen.swift; sourceTree = "<group>"; };
F7BF7222267F0F0C00CE9E58 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
F7BF7225267F0F0C00CE9E58 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
F7BF7227267F0F0C00CE9E58 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
F7BF722E267F0F2800CE9E58 /* ios.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = ios.entitlements; sourceTree = "<group>"; };
F7BF7236267F243D00CE9E58 /* build */ = {isa = PBXFileReference; lastKnownFileType = folder; name = build; path = ../build; sourceTree = "<group>"; };
F7BF7239267F247500CE9E58 /* Bundle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bundle.swift; sourceTree = "<group>"; };
F7BF723C267F248200CE9E58 /* Events.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Events.swift; sourceTree = "<group>"; };
F7BF723F267F248E00CE9E58 /* State.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = State.swift; sourceTree = "<group>"; };
F7BF7242267F24A500CE9E58 /* WebView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
F7BF7218267F0F0A00CE9E58 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
F7BF7212267F0F0A00CE9E58 = {
isa = PBXGroup;
children = (
F7BF7236267F243D00CE9E58 /* build */,
F7BF721D267F0F0A00CE9E58 /* ios */,
F7BF721C267F0F0A00CE9E58 /* Products */,
);
sourceTree = "<group>";
};
F7BF721C267F0F0A00CE9E58 /* Products */ = {
isa = PBXGroup;
children = (
F7BF721B267F0F0A00CE9E58 /* ios.app */,
);
name = Products;
sourceTree = "<group>";
};
F7BF721D267F0F0A00CE9E58 /* ios */ = {
isa = PBXGroup;
children = (
F7BF722E267F0F2800CE9E58 /* ios.entitlements */,
F7BF721E267F0F0A00CE9E58 /* App.swift */,
F7BF7239267F247500CE9E58 /* Bundle.swift */,
F7BF723C267F248200CE9E58 /* Events.swift */,
F7BF7242267F24A500CE9E58 /* WebView.swift */,
F7BF7220267F0F0A00CE9E58 /* Screen.swift */,
F7BF723F267F248E00CE9E58 /* State.swift */,
F7BF7222267F0F0C00CE9E58 /* Assets.xcassets */,
F7BF7227267F0F0C00CE9E58 /* Info.plist */,
F7BF7224267F0F0C00CE9E58 /* Preview Content */,
);
path = ios;
sourceTree = "<group>";
};
F7BF7224267F0F0C00CE9E58 /* Preview Content */ = {
isa = PBXGroup;
children = (
F7BF7225267F0F0C00CE9E58 /* Preview Assets.xcassets */,
);
path = "Preview Content";
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
F7BF721A267F0F0A00CE9E58 /* ios */ = {
isa = PBXNativeTarget;
buildConfigurationList = F7BF722A267F0F0C00CE9E58 /* Build configuration list for PBXNativeTarget "ios" */;
buildPhases = (
F7BF7217267F0F0A00CE9E58 /* Sources */,
F7BF7218267F0F0A00CE9E58 /* Frameworks */,
F7BF7219267F0F0A00CE9E58 /* Resources */,
);
buildRules = (
);
dependencies = (
);
name = ios;
productName = ios;
productReference = F7BF721B267F0F0A00CE9E58 /* ios.app */;
productType = "com.apple.product-type.application";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
F7BF7213267F0F0A00CE9E58 /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 1240;
LastUpgradeCheck = 1240;
TargetAttributes = {
F7BF721A267F0F0A00CE9E58 = {
CreatedOnToolsVersion = 12.4;
};
};
};
buildConfigurationList = F7BF7216267F0F0A00CE9E58 /* Build configuration list for PBXProject "ios" */;
compatibilityVersion = "Xcode 9.3";
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = F7BF7212267F0F0A00CE9E58;
productRefGroup = F7BF721C267F0F0A00CE9E58 /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
F7BF721A267F0F0A00CE9E58 /* ios */,
);
};
/* End PBXProject section */
/* Begin PBXResourcesBuildPhase section */
F7BF7219267F0F0A00CE9E58 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
F7BF7237267F243D00CE9E58 /* build in Resources */,
F7BF7226267F0F0C00CE9E58 /* Preview Assets.xcassets in Resources */,
F7BF7223267F0F0C00CE9E58 /* Assets.xcassets in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
F7BF7217267F0F0A00CE9E58 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
F7BF723D267F248200CE9E58 /* Events.swift in Sources */,
F7BF7221267F0F0A00CE9E58 /* Screen.swift in Sources */,
F7BF723A267F247500CE9E58 /* Bundle.swift in Sources */,
F7BF7243267F24A500CE9E58 /* WebView.swift in Sources */,
F7BF7240267F248E00CE9E58 /* State.swift in Sources */,
F7BF721F267F0F0A00CE9E58 /* App.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin XCBuildConfiguration section */
F7BF7228267F0F0C00CE9E58 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 14.4;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
name = Debug;
};
F7BF7229267F0F0C00CE9E58 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 14.4;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
VALIDATE_PRODUCT = YES;
};
name = Release;
};
F7BF722B267F0F0C00CE9E58 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = ios/ios.entitlements;
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_ASSET_PATHS = "\"ios/Preview Content\"";
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = ios/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.example.ios;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTS_MACCATALYST = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,6";
};
name = Debug;
};
F7BF722C267F0F0C00CE9E58 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = ios/ios.entitlements;
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_ASSET_PATHS = "\"ios/Preview Content\"";
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = ios/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.example.ios;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTS_MACCATALYST = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,6";
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
F7BF7216267F0F0A00CE9E58 /* Build configuration list for PBXProject "ios" */ = {
isa = XCConfigurationList;
buildConfigurations = (
F7BF7228267F0F0C00CE9E58 /* Debug */,
F7BF7229267F0F0C00CE9E58 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
F7BF722A267F0F0C00CE9E58 /* Build configuration list for PBXNativeTarget "ios" */ = {
isa = XCConfigurationList;
buildConfigurations = (
F7BF722B267F0F0C00CE9E58 /* Debug */,
F7BF722C267F0F0C00CE9E58 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = F7BF7213267F0F0A00CE9E58 /* Project object */;
}
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:">
</FileRef>
</Workspace>
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>ios.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
+31
View File
@@ -0,0 +1,31 @@
//
// iosApp.swift
// ios
//
// Created by Rody Davis on 6/19/21.
//
import SwiftUI
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
Screen(
title: "My App",
components: [
Component(
tag: "my-element",
name: "Element 1"
),
]
)
}.commands {
// CommandMenu("Custom Menu") {
// Button("Action 1") {
// print("pressed menu item")
// }
// }
}
}
}
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
@@ -0,0 +1,98 @@
{
"images" : [
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "60x60"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "60x60"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "83.5x83.5"
},
{
"idiom" : "ios-marketing",
"scale" : "1x",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
+117
View File
@@ -0,0 +1,117 @@
//
// Cache.swift
// app
//
// Created by Rody Davis on 6/17/21.
//
import Foundation
struct AppBundle {
let name: String
let url: String
var cacheDays = 1
let appSup = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first!
func get() -> String {
// Start remote download
self.download()
#if DEBUG
#else
// Search for cached bundle
do {
let url = self.appSup.appendingPathComponent(self.prefs.bundle).appendingPathExtension("js")
let bundle: String = try String(contentsOfFile: url.path)
return bundle
} catch {
print("Cached bundle not found", error)
}
#endif
// Fallback to included bundle
do {
let url = Bundle.main.url(forResource: name, withExtension: "js", subdirectory: "build")!
let bundle: String = try String(contentsOfFile: url.path)
self.save(content: bundle)
return bundle
} catch {
print("Local bundle not found", error)
}
// No bundle included
return ""
}
func save(content: String) {
let fileManager = FileManager.default
let bundleUrl = self.appSup.appendingPathComponent(name).appendingPathExtension("js")
// Check if Application Support Exists
if !fileManager.fileExists(atPath: self.appSup.path) {
do {
try fileManager.createDirectory(
at: self.appSup,
withIntermediateDirectories: true,
attributes: nil
)
} catch {
print("Could not create app support directory", error)
}
}
// Fallback to bundle included at compile time
if fileManager.fileExists(atPath: bundleUrl.path) {
do {
try fileManager.removeItem(at: bundleUrl)
} catch {
print("Could not remove existing bundle", error)
}
}
// Update the bundle
do {
try content.write(to: bundleUrl, atomically: true, encoding: String.Encoding.utf8)
} catch {
print("Error updating bundle", error)
}
}
func download() {
if url.isEmpty { return }
if let url = URL(string: url + "/" + name) {
let key = "last-bundle-update";
// Check if the bundle has already been downloaded
if let value = UserDefaults.standard.object(forKey: key) as? Date {
if Calendar.current.daysSince(date: value) ?? -1 < cacheDays {
return
}
}
// Try downloading a new bundle from the network
let downloadTask = URLSession.shared.downloadTask(with: url) { (tempUrl, response, error) in
if let tempFileUrl = tempUrl {
do {
let remoteBundle = try String(contentsOf: tempFileUrl)
self.save(content: remoteBundle)
UserDefaults.standard.set(Date(), forKey: key)
} catch {
print("Error downloading bundle", error)
}
}
}
downloadTask.resume()
}
}
}
extension Calendar {
public func daysSince(date: Date) -> Int? {
return self.dateComponents([.day], from: date, to: Date()).day
}
}
+41
View File
@@ -0,0 +1,41 @@
//
// Events.swift
// app
//
// Created by Rody Davis on 6/19/21.
//
import Foundation
import WebKit
func handleEvent(_ webview: WKWebView, message: WKScriptMessage) {
guard let dict = message.body as? [String : AnyObject],
let type = dict["type"] as? String else {
return
}
switch type {
case "dialog":
let title = dict["title"] as! String
let message = dict["message"] as! String
showAlert(title: title, message: message) {
webview.dispatchEvent(event: "response", detail: "WebKit")
}
break
default:
print("event", dict)
}
}
func showAlert(title: String, message: String, callback: @escaping () -> Void) -> Void {
let alert = UIAlertController(title:title,
message: message,
preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Ok", style: .default){ action -> Void in
callback()
})
let vc = UIApplication.shared.windows.first?.rootViewController
vc?.present(alert, animated: true, completion: nil)
}
+56
View File
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AppBundleName</key>
<string>bundle.es</string>
<key>AppUrl</key>
<string></string>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>My App</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<true/>
</dict>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>UILaunchScreen</key>
<dict/>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
+60
View File
@@ -0,0 +1,60 @@
//
// ContentView.swift
// ios
//
// Created by Rody Davis on 6/19/21.
//
import SwiftUI
struct Screen: View {
@StateObject var state = AppState()
@State var title: String
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
let components: [Component]
var body: some View {
if (components.count == 1 && title.count > 0) {
let item = components[0]
if (horizontalSizeClass == .compact) {
NavigationView {
RenderComponent(component: item)
}.navigationTitle(title)
} else {
RenderComponent(component: item)
}
} else {
NavigationView {
List(components) { item in
NavigationLink(destination: RenderComponent(component: item)
) {
Text(item.name)
}
}.navigationTitle(title)
}
}
}
}
struct RenderComponent: View {
let component: Component
var body: some View {
GeometryReader { geometry in
ZStack {
WebView(
tag: component.tag,
size: geometry.size
)
}}
.navigationBarTitle( component.name, displayMode: .automatic)
}
}
struct Component: Codable, Identifiable {
var id = UUID()
let tag: String
let name: String
var icon: String = "phone.fill"
var bundle: String = "bundle.es"
}
+19
View File
@@ -0,0 +1,19 @@
//
// Config.swift
// app
//
// Created by Rody Davis on 6/16/21.
//
import Foundation
import SwiftUI
class AppState: ObservableObject {
@Published var title = Bundle.main.infoDictionary!["CFBundleName"] as! String
@Published var url = Bundle.main.infoDictionary!["AppUrl"] as! String
@Published var bundle = Bundle.main.infoDictionary!["AppBundleName"] as! String
@Published var hideStatusBar = false
@Published var hideNavigationBar = false
@Published var cacheDays = 1
@Published var component = "my-element"
}
+140
View File
@@ -0,0 +1,140 @@
//
// WebView.swift
// app
//
// Created by Rody Davis on 6/16/21.
//
import Foundation
import SwiftUI
import WebKit
struct WebView: UIViewControllerRepresentable {
let tag: String
let size: CGSize
var title: String = ""
var bundle: String = "bundle.es"
var url: String = ""
let webview: WKWebView = WKWebView()
func makeUIViewController(context: Context) -> WebViewController {
let vc = WebViewController()
vc.setBundle(bundle: AppBundle(name: bundle, url: url))
vc.context = self
return vc
}
func updateUIViewController(_ webviewController: WebViewController, context: Context) {
webviewController.resize(size: size)
}
}
class WebViewController: UIViewController, WKNavigationDelegate, WKUIDelegate, WKScriptMessageHandler, UIWindowSceneDelegate {
lazy var context: WebView? = nil
lazy var bundle: AppBundle? = nil
let config = WKWebViewConfiguration()
lazy var webview: WKWebView = WKWebView()
func resize(size: CGSize) {
webview.frame = CGRect(x: 0 , y: 0, width: size.width, height: size.height)
}
override func viewDidLoad() {
super.viewDidLoad()
webview = WKWebView(frame: .zero, configuration: config)
webview.invalidateIntrinsicContentSize()
webview.translatesAutoresizingMaskIntoConstraints = true
webview.autoresizesSubviews = true
webview.contentMode = .redraw
webview.configuration.mediaTypesRequiringUserActionForPlayback = []
webview.isHidden = false
webview.configuration.allowsInlineMediaPlayback = false
webview.scrollView.bounces = false
webview.scrollView.isScrollEnabled = false
webview.isOpaque = false
webview.navigationDelegate = self
webview.uiDelegate = self
webview.frame = view.frame
webview.configuration.userContentController.add(self, name: "handler")
loadHtml()
view.addSubview(webview)
}
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
switch keyPath {
default:
super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)
}
}
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
handleEvent(webview, message: message)
}
func loadHtml() {
webview.configuration.defaultWebpagePreferences.allowsContentJavaScript = true
addScript(source: bundle!.get())
addScript(source: eventScript())
webview.loadHTMLString(getHTML(title: context!.title), baseURL: nil)
}
func addScript(source: String) {
let script = WKUserScript(source: source, injectionTime: .atDocumentEnd, forMainFrameOnly: true)
webview.configuration.userContentController.addUserScript(script)
}
func setBundle(bundle: AppBundle) {
self.bundle = bundle
}
func getHTML(title: String = "", slot: String = "") -> String {
return """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no" />
<title>\(title)</title>
<style>
body {
width: 100%;
height: 100vh;
padding: 0;
margin: 0;
}
</style>
</head>
<body>
<\(context!.tag)>
\(slot)
</\(context!.tag)>
</body>
</html>
"""
}
func eventScript() -> String {
return """
document.addEventListener('native', (e) => {
window.webkit.messageHandlers.handler.postMessage(e.detail);
}, false);
"""
}
}
extension WKWebView {
public func dispatchEvent(event: String, detail: String) -> Void {
let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted
let data = try! encoder.encode(["event": event, "detail": detail])
let jsonString = String(data: data, encoding: .utf8)!
let script = """
const elem = document.querySelector('my-element')
elem.dispatchEvent(new CustomEvent('response', { detail: \(jsonString) }))
"""
self.evaluateJavaScript(script)
}
}
+12
View File
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
<key>com.apple.security.network.server</key>
<true/>
</dict>
</plist>