sinho 0.1.0

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.
Files changed (117) hide show
  1. package/.github/workflows/ci.yml +24 -0
  2. package/.github/workflows/deploy-docs.yml +47 -0
  3. package/.prettierrc +3 -0
  4. package/LICENSE.md +21 -0
  5. package/README.md +33 -0
  6. package/ci/check-size.js +8 -0
  7. package/dist/array_mutation.d.ts +16 -0
  8. package/dist/array_mutation.js +75 -0
  9. package/dist/array_mutation.js.map +1 -0
  10. package/dist/bundle.d.ts +1126 -0
  11. package/dist/bundle.js +1074 -0
  12. package/dist/bundle.min.js +1 -0
  13. package/dist/component.d.ts +253 -0
  14. package/dist/component.js +256 -0
  15. package/dist/component.js.map +1 -0
  16. package/dist/context.d.ts +21 -0
  17. package/dist/context.js +34 -0
  18. package/dist/context.js.map +1 -0
  19. package/dist/create_element.d.ts +43 -0
  20. package/dist/create_element.js +43 -0
  21. package/dist/create_element.js.map +1 -0
  22. package/dist/dom.d.ts +602 -0
  23. package/dist/dom.js +97 -0
  24. package/dist/dom.js.map +1 -0
  25. package/dist/intrinsic/ClassComponent.d.ts +2 -0
  26. package/dist/intrinsic/ClassComponent.js +10 -0
  27. package/dist/intrinsic/ClassComponent.js.map +1 -0
  28. package/dist/intrinsic/Dynamic.d.ts +33 -0
  29. package/dist/intrinsic/Dynamic.js +53 -0
  30. package/dist/intrinsic/Dynamic.js.map +1 -0
  31. package/dist/intrinsic/ErrorBoundary.d.ts +14 -0
  32. package/dist/intrinsic/ErrorBoundary.js +36 -0
  33. package/dist/intrinsic/ErrorBoundary.js.map +1 -0
  34. package/dist/intrinsic/For.d.ts +10 -0
  35. package/dist/intrinsic/For.js +81 -0
  36. package/dist/intrinsic/For.js.map +1 -0
  37. package/dist/intrinsic/Fragment.d.ts +23 -0
  38. package/dist/intrinsic/Fragment.js +28 -0
  39. package/dist/intrinsic/Fragment.js.map +1 -0
  40. package/dist/intrinsic/If.d.ts +24 -0
  41. package/dist/intrinsic/If.js +47 -0
  42. package/dist/intrinsic/If.js.map +1 -0
  43. package/dist/intrinsic/Portal.d.ts +6 -0
  44. package/dist/intrinsic/Portal.js +15 -0
  45. package/dist/intrinsic/Portal.js.map +1 -0
  46. package/dist/intrinsic/Style.d.ts +7 -0
  47. package/dist/intrinsic/Style.js +70 -0
  48. package/dist/intrinsic/Style.js.map +1 -0
  49. package/dist/intrinsic/TagComponent.d.ts +4 -0
  50. package/dist/intrinsic/TagComponent.js +67 -0
  51. package/dist/intrinsic/TagComponent.js.map +1 -0
  52. package/dist/intrinsic/Text.d.ts +6 -0
  53. package/dist/intrinsic/Text.js +16 -0
  54. package/dist/intrinsic/Text.js.map +1 -0
  55. package/dist/intrinsic/mod.d.ts +5 -0
  56. package/dist/intrinsic/mod.js +6 -0
  57. package/dist/intrinsic/mod.js.map +1 -0
  58. package/dist/jsx-runtime/mod.d.ts +23 -0
  59. package/dist/jsx-runtime/mod.js +11 -0
  60. package/dist/jsx-runtime/mod.js.map +1 -0
  61. package/dist/mod.d.ts +8 -0
  62. package/dist/mod.js +7 -0
  63. package/dist/mod.js.map +1 -0
  64. package/dist/renderer.d.ts +13 -0
  65. package/dist/renderer.js +25 -0
  66. package/dist/renderer.js.map +1 -0
  67. package/dist/scope.d.ts +138 -0
  68. package/dist/scope.js +228 -0
  69. package/dist/scope.js.map +1 -0
  70. package/dist/template.d.ts +10 -0
  71. package/dist/template.js +7 -0
  72. package/dist/template.js.map +1 -0
  73. package/dist/utils.d.ts +6 -0
  74. package/dist/utils.js +13 -0
  75. package/dist/utils.js.map +1 -0
  76. package/package.json +71 -0
  77. package/src/array_mutation.ts +118 -0
  78. package/src/component.ts +624 -0
  79. package/src/context.ts +70 -0
  80. package/src/create_element.ts +89 -0
  81. package/src/dom.ts +819 -0
  82. package/src/intrinsic/ClassComponent.ts +17 -0
  83. package/src/intrinsic/For.ts +122 -0
  84. package/src/intrinsic/Fragment.ts +38 -0
  85. package/src/intrinsic/If.ts +73 -0
  86. package/src/intrinsic/Portal.ts +25 -0
  87. package/src/intrinsic/Style.ts +120 -0
  88. package/src/intrinsic/TagComponent.ts +102 -0
  89. package/src/intrinsic/Text.ts +24 -0
  90. package/src/intrinsic/mod.ts +5 -0
  91. package/src/jsx-runtime/mod.ts +41 -0
  92. package/src/mod.ts +37 -0
  93. package/src/renderer.ts +45 -0
  94. package/src/scope.ts +404 -0
  95. package/src/template.ts +16 -0
  96. package/src/utils.ts +29 -0
  97. package/terser.config.json +16 -0
  98. package/tsconfig.json +18 -0
  99. package/web/README.md +41 -0
  100. package/web/babel.config.js +3 -0
  101. package/web/dist/shingo.min.d.ts +1131 -0
  102. package/web/dist/shingo.min.js +1 -0
  103. package/web/docusaurus.config.ts +151 -0
  104. package/web/package-lock.json +14850 -0
  105. package/web/package.json +54 -0
  106. package/web/sidebars.ts +31 -0
  107. package/web/src/components/monacoEditor.tsx +72 -0
  108. package/web/src/components/playground.tsx +89 -0
  109. package/web/src/components/playgroundComponent.tsx +168 -0
  110. package/web/src/css/custom.css +37 -0
  111. package/web/src/pages/index.module.css +31 -0
  112. package/web/src/pages/index.tsx +73 -0
  113. package/web/src/pages/playground.tsx +64 -0
  114. package/web/static/.nojekyll +0 -0
  115. package/web/static/dist/bundle.d.ts +1126 -0
  116. package/web/static/dist/bundle.min.js +1 -0
  117. package/web/tsconfig.json +8 -0
@@ -0,0 +1,89 @@
1
+ import {
2
+ ComponentConstructor,
3
+ FunctionalComponent,
4
+ isComponent,
5
+ JsxProps,
6
+ } from "./component.js";
7
+ import { DomIntrinsicElements, DomProps } from "./dom.js";
8
+ import { Children } from "./intrinsic/Fragment.js";
9
+ import { TagComponent } from "./intrinsic/TagComponent.js";
10
+ import { ClassComponent } from "./intrinsic/ClassComponent.js";
11
+ import { Template, createTemplate } from "./template.js";
12
+
13
+ /**
14
+ * Creates a template based on the given component type.
15
+ *
16
+ * @example
17
+ * ```tsx
18
+ * render() {
19
+ * return createElement("div", { id: "app" }, [
20
+ * createElement("h1", {}, "Hello, World!"),
21
+ * ]);
22
+ * }
23
+ * ```
24
+ */
25
+ export const createElement: (<K extends keyof DomIntrinsicElements & string>(
26
+ type: K,
27
+ props?: DomIntrinsicElements[K],
28
+ children?: Children,
29
+ ) => Template) &
30
+ (<T extends HTMLElement>(
31
+ ...args: [
32
+ type: new () => T,
33
+ ...({} extends JsxProps<T>
34
+ ? [props?: JsxProps<T>]
35
+ : [props: JsxProps<T>]),
36
+ children?: DomProps<T>["children"],
37
+ ]
38
+ ) => Template) &
39
+ (<P extends object>(
40
+ ...args: [
41
+ type: FunctionalComponent<P>,
42
+ ...({} extends P ? [props?: P] : [props: P]),
43
+ ...(P extends { children?: unknown }
44
+ ? undefined extends P["children"]
45
+ ? [children?: P["children"]]
46
+ : [children: P["children"]]
47
+ : []),
48
+ ]
49
+ ) => Template) = ((
50
+ type:
51
+ | (keyof DomIntrinsicElements & string)
52
+ | ComponentConstructor
53
+ | FunctionalComponent,
54
+ props: Record<string, unknown> = {},
55
+ children?: Children,
56
+ ): Template => {
57
+ if (children != null) {
58
+ (props as any).children = children;
59
+ }
60
+
61
+ return isComponent(type)
62
+ ? ClassComponent(type, props)
63
+ : typeof type == "function"
64
+ ? createTemplate(() => type(props))
65
+ : TagComponent(type, props);
66
+ }) as any;
67
+
68
+ /**
69
+ * Shorthand for {@link createElement} with convenience methods for intrinsic
70
+ * elements.
71
+ *
72
+ * @example
73
+ * ```tsx
74
+ * render() {
75
+ * return h.div({ id: "app" }, [
76
+ * h.h1({}, "Hello, World!"),
77
+ * ]);
78
+ * }
79
+ * ```
80
+ */
81
+ export const h: typeof createElement & {
82
+ [K in keyof DomIntrinsicElements]: (
83
+ props?: DomIntrinsicElements[K],
84
+ children?: Children,
85
+ ) => Template;
86
+ } = new Proxy(createElement, {
87
+ get: (target, type) => (props?: object, children?: Children) =>
88
+ target(type as string, props, children),
89
+ }) as any;