isomorfeus-preact 10.8.2 → 22.9.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +14 -3
- data/README.md +23 -39
- data/lib/browser/delegate_native.rb +94 -72
- data/lib/browser/document.rb +38 -0
- data/lib/browser/element.rb +160 -176
- data/lib/browser/event.rb +99 -94
- data/lib/browser/history.rb +40 -20
- data/lib/browser/location.rb +59 -0
- data/lib/browser/window.rb +58 -0
- data/lib/data_uri/open_uri.rb +18 -0
- data/lib/data_uri/uri.rb +61 -0
- data/lib/data_uri.rb +4 -0
- data/lib/isomorfeus/preact/config.rb +42 -54
- data/lib/isomorfeus/preact/imports.rb +5 -20
- data/lib/isomorfeus/preact/ssr.rb +34 -0
- data/lib/isomorfeus/preact/thread_local_component_cache.rb +9 -11
- data/lib/isomorfeus/preact/version.rb +5 -0
- data/lib/isomorfeus/preact/view_helper.rb +72 -0
- data/lib/isomorfeus/props/validator.rb +19 -11
- data/lib/isomorfeus/top_level.rb +55 -33
- data/lib/isomorfeus-preact.rb +78 -103
- data/lib/link.rb +52 -0
- data/lib/lucid_app.rb +117 -0
- data/lib/lucid_component.rb +154 -0
- data/lib/nano_css.rb +282 -465
- data/lib/preact/component.rb +222 -0
- data/lib/preact/component_resolution.rb +49 -83
- data/lib/preact/context.rb +68 -0
- data/lib/preact/elements.rb +2 -9
- data/lib/preact/module_component_resolution.rb +50 -0
- data/lib/preact/prop_declaration_mixin.rb +73 -0
- data/lib/preact.rb +1548 -257
- data/lib/redirect.rb +34 -0
- data/lib/route.rb +15 -0
- data/lib/router.rb +145 -0
- data/lib/switch.rb +70 -0
- metadata +42 -309
- data/lib/isomorfeus/preact/memcached_component_cache.rb +0 -19
- data/lib/isomorfeus/preact/redis_component_cache.rb +0 -19
- data/lib/isomorfeus/preact/ssr/history.rb +0 -23
- data/lib/isomorfeus/preact/ssr/render_core.rb +0 -117
- data/lib/isomorfeus/preact/ssr/top_level.rb +0 -37
- data/lib/isomorfeus/preact_view_helper.rb +0 -129
- data/lib/isomorfeus_preact/lucid_app/api.rb +0 -38
- data/lib/isomorfeus_preact/lucid_app/base.rb +0 -7
- data/lib/isomorfeus_preact/lucid_app/mixin.rb +0 -14
- data/lib/isomorfeus_preact/lucid_app/native_component_constructor.rb +0 -101
- data/lib/isomorfeus_preact/lucid_component/api.rb +0 -123
- data/lib/isomorfeus_preact/lucid_component/app_store_proxy.rb +0 -32
- data/lib/isomorfeus_preact/lucid_component/base.rb +0 -7
- data/lib/isomorfeus_preact/lucid_component/class_store_proxy.rb +0 -37
- data/lib/isomorfeus_preact/lucid_component/initializer.rb +0 -9
- data/lib/isomorfeus_preact/lucid_component/mixin.rb +0 -13
- data/lib/isomorfeus_preact/lucid_component/native_component_constructor.rb +0 -87
- data/lib/isomorfeus_preact/lucid_component/styles_wrapper.rb +0 -40
- data/lib/isomorfeus_preact/lucid_func/base.rb +0 -7
- data/lib/isomorfeus_preact/lucid_func/initializer.rb +0 -8
- data/lib/isomorfeus_preact/lucid_func/mixin.rb +0 -10
- data/lib/isomorfeus_preact/lucid_func/native_component_constructor.rb +0 -56
- data/lib/isomorfeus_preact/preact/function_component/api.rb +0 -140
- data/lib/isomorfeus_preact/preact/function_component/base.rb +0 -7
- data/lib/isomorfeus_preact/preact/function_component/initializer.rb +0 -6
- data/lib/isomorfeus_preact/preact/function_component/mixin.rb +0 -8
- data/lib/isomorfeus_preact/preact/function_component/native_component_constructor.rb +0 -47
- data/lib/lucid_app/context.rb +0 -24
- data/lib/lucid_prop_declaration/mixin.rb +0 -126
- data/lib/preact/component/api.rb +0 -137
- data/lib/preact/component/base.rb +0 -7
- data/lib/preact/component/callbacks.rb +0 -111
- data/lib/preact/component/initializer.rb +0 -7
- data/lib/preact/component/mixin.rb +0 -11
- data/lib/preact/component/native_component_constructor.rb +0 -77
- data/lib/preact/context_wrapper.rb +0 -48
- data/lib/preact/native_constant_wrapper.rb +0 -29
- data/lib/preact/option_hooks.rb +0 -98
- data/lib/preact/params.rb +0 -16
- data/lib/preact/props.rb +0 -69
- data/lib/preact/ref.rb +0 -17
- data/lib/preact/state.rb +0 -87
- data/lib/preact/version.rb +0 -3
- data/node_modules/.package-lock.json +0 -38
- data/node_modules/preact/LICENSE +0 -21
- data/node_modules/preact/README.md +0 -188
- data/node_modules/preact/compat/LICENSE +0 -21
- data/node_modules/preact/compat/client.js +0 -19
- data/node_modules/preact/compat/client.mjs +0 -17
- data/node_modules/preact/compat/dist/compat.js +0 -2
- data/node_modules/preact/compat/dist/compat.js.map +0 -1
- data/node_modules/preact/compat/dist/compat.mjs +0 -2
- data/node_modules/preact/compat/dist/compat.module.js +0 -2
- data/node_modules/preact/compat/dist/compat.module.js.map +0 -1
- data/node_modules/preact/compat/dist/compat.umd.js +0 -2
- data/node_modules/preact/compat/dist/compat.umd.js.map +0 -1
- data/node_modules/preact/compat/jsx-dev-runtime.js +0 -3
- data/node_modules/preact/compat/jsx-dev-runtime.mjs +0 -3
- data/node_modules/preact/compat/jsx-runtime.js +0 -3
- data/node_modules/preact/compat/jsx-runtime.mjs +0 -3
- data/node_modules/preact/compat/package.json +0 -49
- data/node_modules/preact/compat/scheduler.js +0 -15
- data/node_modules/preact/compat/scheduler.mjs +0 -23
- data/node_modules/preact/compat/server.browser.js +0 -4
- data/node_modules/preact/compat/server.js +0 -15
- data/node_modules/preact/compat/server.mjs +0 -4
- data/node_modules/preact/compat/src/Children.js +0 -21
- data/node_modules/preact/compat/src/PureComponent.js +0 -15
- data/node_modules/preact/compat/src/forwardRef.js +0 -44
- data/node_modules/preact/compat/src/index.d.ts +0 -155
- data/node_modules/preact/compat/src/index.js +0 -187
- data/node_modules/preact/compat/src/internal.d.ts +0 -47
- data/node_modules/preact/compat/src/memo.js +0 -34
- data/node_modules/preact/compat/src/portals.js +0 -82
- data/node_modules/preact/compat/src/render.js +0 -238
- data/node_modules/preact/compat/src/suspense-list.d.ts +0 -14
- data/node_modules/preact/compat/src/suspense-list.js +0 -126
- data/node_modules/preact/compat/src/suspense.d.ts +0 -15
- data/node_modules/preact/compat/src/suspense.js +0 -270
- data/node_modules/preact/compat/src/util.js +0 -28
- data/node_modules/preact/compat/test-utils.js +0 -1
- data/node_modules/preact/debug/LICENSE +0 -21
- data/node_modules/preact/debug/dist/debug.js +0 -2
- data/node_modules/preact/debug/dist/debug.js.map +0 -1
- data/node_modules/preact/debug/dist/debug.mjs +0 -2
- data/node_modules/preact/debug/dist/debug.module.js +0 -2
- data/node_modules/preact/debug/dist/debug.module.js.map +0 -1
- data/node_modules/preact/debug/dist/debug.umd.js +0 -2
- data/node_modules/preact/debug/dist/debug.umd.js.map +0 -1
- data/node_modules/preact/debug/package.json +0 -26
- data/node_modules/preact/debug/src/check-props.js +0 -54
- data/node_modules/preact/debug/src/component-stack.js +0 -146
- data/node_modules/preact/debug/src/constants.js +0 -3
- data/node_modules/preact/debug/src/debug.js +0 -437
- data/node_modules/preact/debug/src/index.js +0 -6
- data/node_modules/preact/debug/src/internal.d.ts +0 -82
- data/node_modules/preact/debug/src/util.js +0 -11
- data/node_modules/preact/devtools/LICENSE +0 -21
- data/node_modules/preact/devtools/dist/devtools.js +0 -2
- data/node_modules/preact/devtools/dist/devtools.js.map +0 -1
- data/node_modules/preact/devtools/dist/devtools.mjs +0 -2
- data/node_modules/preact/devtools/dist/devtools.module.js +0 -2
- data/node_modules/preact/devtools/dist/devtools.module.js.map +0 -1
- data/node_modules/preact/devtools/dist/devtools.umd.js +0 -2
- data/node_modules/preact/devtools/dist/devtools.umd.js.map +0 -1
- data/node_modules/preact/devtools/package.json +0 -25
- data/node_modules/preact/devtools/src/devtools.js +0 -10
- data/node_modules/preact/devtools/src/index.d.ts +0 -8
- data/node_modules/preact/devtools/src/index.js +0 -15
- data/node_modules/preact/dist/preact.js +0 -2
- data/node_modules/preact/dist/preact.js.map +0 -1
- data/node_modules/preact/dist/preact.min.js +0 -2
- data/node_modules/preact/dist/preact.min.js.map +0 -1
- data/node_modules/preact/dist/preact.mjs +0 -2
- data/node_modules/preact/dist/preact.module.js +0 -2
- data/node_modules/preact/dist/preact.module.js.map +0 -1
- data/node_modules/preact/dist/preact.umd.js +0 -2
- data/node_modules/preact/dist/preact.umd.js.map +0 -1
- data/node_modules/preact/hooks/LICENSE +0 -21
- data/node_modules/preact/hooks/dist/hooks.js +0 -2
- data/node_modules/preact/hooks/dist/hooks.js.map +0 -1
- data/node_modules/preact/hooks/dist/hooks.mjs +0 -2
- data/node_modules/preact/hooks/dist/hooks.module.js +0 -2
- data/node_modules/preact/hooks/dist/hooks.module.js.map +0 -1
- data/node_modules/preact/hooks/dist/hooks.umd.js +0 -2
- data/node_modules/preact/hooks/dist/hooks.umd.js.map +0 -1
- data/node_modules/preact/hooks/package.json +0 -35
- data/node_modules/preact/hooks/src/index.d.ts +0 -139
- data/node_modules/preact/hooks/src/index.js +0 -417
- data/node_modules/preact/hooks/src/internal.d.ts +0 -78
- data/node_modules/preact/jsx-runtime/LICENSE +0 -21
- data/node_modules/preact/jsx-runtime/dist/jsxRuntime.js +0 -2
- data/node_modules/preact/jsx-runtime/dist/jsxRuntime.js.map +0 -1
- data/node_modules/preact/jsx-runtime/dist/jsxRuntime.mjs +0 -2
- data/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js +0 -2
- data/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js.map +0 -1
- data/node_modules/preact/jsx-runtime/dist/jsxRuntime.umd.js +0 -2
- data/node_modules/preact/jsx-runtime/dist/jsxRuntime.umd.js.map +0 -1
- data/node_modules/preact/jsx-runtime/package.json +0 -28
- data/node_modules/preact/jsx-runtime/src/index.d.ts +0 -50
- data/node_modules/preact/jsx-runtime/src/index.js +0 -77
- data/node_modules/preact/package.json +0 -304
- data/node_modules/preact/src/cjs.js +0 -3
- data/node_modules/preact/src/clone-element.js +0 -34
- data/node_modules/preact/src/component.js +0 -225
- data/node_modules/preact/src/constants.js +0 -3
- data/node_modules/preact/src/create-context.js +0 -68
- data/node_modules/preact/src/create-element.js +0 -98
- data/node_modules/preact/src/diff/catch-error.js +0 -40
- data/node_modules/preact/src/diff/children.js +0 -335
- data/node_modules/preact/src/diff/index.js +0 -533
- data/node_modules/preact/src/diff/props.js +0 -158
- data/node_modules/preact/src/index.d.ts +0 -317
- data/node_modules/preact/src/index.js +0 -13
- data/node_modules/preact/src/internal.d.ts +0 -155
- data/node_modules/preact/src/jsx.d.ts +0 -1013
- data/node_modules/preact/src/options.js +0 -16
- data/node_modules/preact/src/render.js +0 -75
- data/node_modules/preact/src/util.js +0 -27
- data/node_modules/preact/test-utils/dist/testUtils.js +0 -2
- data/node_modules/preact/test-utils/dist/testUtils.js.map +0 -1
- data/node_modules/preact/test-utils/dist/testUtils.mjs +0 -2
- data/node_modules/preact/test-utils/dist/testUtils.module.js +0 -2
- data/node_modules/preact/test-utils/dist/testUtils.module.js.map +0 -1
- data/node_modules/preact/test-utils/dist/testUtils.umd.js +0 -2
- data/node_modules/preact/test-utils/dist/testUtils.umd.js.map +0 -1
- data/node_modules/preact/test-utils/package.json +0 -28
- data/node_modules/preact/test-utils/src/index.d.ts +0 -3
- data/node_modules/preact/test-utils/src/index.js +0 -118
- data/node_modules/preact-render-to-string/LICENSE +0 -21
- data/node_modules/preact-render-to-string/README.md +0 -102
- data/node_modules/preact-render-to-string/dist/commonjs.js +0 -2
- data/node_modules/preact-render-to-string/dist/commonjs.js.map +0 -1
- data/node_modules/preact-render-to-string/dist/index.d.ts +0 -16
- data/node_modules/preact-render-to-string/dist/index.js +0 -1
- data/node_modules/preact-render-to-string/dist/index.js.map +0 -1
- data/node_modules/preact-render-to-string/dist/index.mjs +0 -2
- data/node_modules/preact-render-to-string/dist/index.module.js +0 -2
- data/node_modules/preact-render-to-string/dist/index.module.js.map +0 -1
- data/node_modules/preact-render-to-string/dist/jsx-entry.js +0 -2
- data/node_modules/preact-render-to-string/dist/jsx-entry.js.map +0 -1
- data/node_modules/preact-render-to-string/dist/jsx.d.ts +0 -13
- data/node_modules/preact-render-to-string/dist/jsx.js +0 -1
- data/node_modules/preact-render-to-string/dist/jsx.js.map +0 -1
- data/node_modules/preact-render-to-string/dist/jsx.mjs +0 -2
- data/node_modules/preact-render-to-string/dist/jsx.modern.js +0 -2
- data/node_modules/preact-render-to-string/dist/jsx.modern.js.map +0 -1
- data/node_modules/preact-render-to-string/dist/jsx.module.js +0 -2
- data/node_modules/preact-render-to-string/dist/jsx.module.js.map +0 -1
- data/node_modules/preact-render-to-string/dist/preact-render-to-string-tests.d.ts +0 -1
- data/node_modules/preact-render-to-string/jsx.js +0 -1
- data/node_modules/preact-render-to-string/package.json +0 -142
- data/node_modules/preact-render-to-string/src/index.d.ts +0 -16
- data/node_modules/preact-render-to-string/src/index.js +0 -462
- data/node_modules/preact-render-to-string/src/jsx.d.ts +0 -13
- data/node_modules/preact-render-to-string/src/jsx.js +0 -76
- data/node_modules/preact-render-to-string/src/polyfills.js +0 -8
- data/node_modules/preact-render-to-string/src/preact-render-to-string-tests.d.ts +0 -1
- data/node_modules/preact-render-to-string/src/util.js +0 -78
- data/node_modules/preact-render-to-string/typings.json +0 -5
- data/node_modules/pretty-format/.npmignore +0 -3
- data/node_modules/pretty-format/LICENSE.md +0 -15
- data/node_modules/pretty-format/README.md +0 -94
- data/node_modules/pretty-format/index.js +0 -343
- data/node_modules/pretty-format/package.json +0 -26
- data/node_modules/pretty-format/plugins/ReactElement.js +0 -74
- data/node_modules/pretty-format/plugins/ReactTestComponent.js +0 -58
- data/node_modules/pretty-format/printString.js +0 -7
- data/node_modules/wouter-preact/cjs/index.js +0 -180
- data/node_modules/wouter-preact/cjs/matcher.js +0 -72
- data/node_modules/wouter-preact/cjs/package.json +0 -1
- data/node_modules/wouter-preact/cjs/react-deps.js +0 -75
- data/node_modules/wouter-preact/cjs/static-location.js +0 -21
- data/node_modules/wouter-preact/cjs/use-location.js +0 -94
- data/node_modules/wouter-preact/index.d.ts +0 -110
- data/node_modules/wouter-preact/index.js +0 -178
- data/node_modules/wouter-preact/matcher.d.ts +0 -30
- data/node_modules/wouter-preact/matcher.js +0 -66
- data/node_modules/wouter-preact/package.json +0 -33
- data/node_modules/wouter-preact/react-deps.js +0 -15
- data/node_modules/wouter-preact/static-location.d.ts +0 -16
- data/node_modules/wouter-preact/static-location.js +0 -17
- data/node_modules/wouter-preact/use-location.d.ts +0 -43
- data/node_modules/wouter-preact/use-location.js +0 -86
- data/package.json +0 -8
data/lib/nano_css.rb
CHANGED
@@ -1,481 +1,298 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
1
|
+
class NanoCSS
|
2
|
+
KEBAB_REGEX = /[A-Z]/
|
3
|
+
UNITLESS_NUMBER_PROPS = %w[animation-iteration-count border-image-outset border-image-slice
|
4
|
+
border-image-width box-flex box-flex-group box-ordinal-group column-count columns flex
|
5
|
+
flex-grow flex-positive flex-shrink flex-negative flex-order grid-row grid-row-end
|
6
|
+
grid-row-span grid-row-start grid-column grid-column-end grid-column-span grid-column-start
|
7
|
+
font-weight line-clamp line-height opacity order orphans tabSize widows z-index zoom
|
8
|
+
fill-opacity flood-opacity stop-opacity stroke-dasharray stroke-dashoffset stroke-miterlimit
|
9
|
+
stroke-opacity stroke-width] # from fill-opacity onwards is for SVG
|
10
|
+
|
11
|
+
class << self
|
12
|
+
if RUBY_ENGINE == 'opal'
|
13
|
+
def instance
|
14
|
+
@instance
|
15
|
+
end
|
16
|
+
|
17
|
+
def instance=(i)
|
18
|
+
@instance = i
|
19
|
+
end
|
20
|
+
else
|
21
|
+
def instance
|
22
|
+
i = Thread.current[:@_isomorfeus_preact_nanocss_instance]
|
23
|
+
return i if i
|
24
|
+
@global_instance
|
25
|
+
end
|
26
|
+
|
27
|
+
def instance=(i)
|
28
|
+
@global_instance = i unless @global_instance
|
29
|
+
Thread.current[:@_isomorfeus_preact_nanocss_instance] = i
|
30
|
+
end
|
31
|
+
|
32
|
+
def global_instance
|
33
|
+
@global_instance
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
@@unitless_css_properties = nil
|
39
|
+
|
40
|
+
attr_reader :renderer
|
41
|
+
|
42
|
+
def initialize(config = nil, given_renderer: nil)
|
43
|
+
config = {} unless config
|
44
|
+
if RUBY_ENGINE == 'opal'
|
45
|
+
@client = `typeof window === "object"`
|
46
|
+
else
|
47
|
+
@client = false
|
48
|
+
end
|
49
|
+
|
50
|
+
if given_renderer
|
51
|
+
@renderer = given_renderer
|
52
|
+
else
|
53
|
+
@renderer = { raw: '', pfx: '_', hydrate_force_put: false, prefixes: ['-webkit-', '-moz-', '-o-', ''] }
|
54
|
+
@renderer.merge!(config)
|
55
|
+
end
|
56
|
+
|
57
|
+
@hydrated = {}
|
58
|
+
|
59
|
+
if @client
|
60
|
+
unless @renderer.key?(:sh)
|
61
|
+
e = `document.createElement('style')`
|
62
|
+
@renderer[:sh] = e
|
63
|
+
`document.head.appendChild(e)`
|
64
|
+
end
|
65
|
+
|
66
|
+
unless @renderer.key?(:kh)
|
67
|
+
e = `document.createElement('style')`
|
68
|
+
@renderer[:ksh] = e
|
69
|
+
`document.head.appendChild(e)`
|
70
|
+
end
|
71
|
+
|
72
|
+
hydrate(@renderer[:sh])
|
73
|
+
end
|
74
|
+
|
75
|
+
unless @@unitless_css_properties
|
76
|
+
@@unitless_css_properties = {}
|
77
|
+
UNITLESS_NUMBER_PROPS.each do |prop|
|
78
|
+
@@unitless_css_properties[prop] = 1
|
79
|
+
@@unitless_css_properties['-webkit-' + prop] = 1
|
80
|
+
@@unitless_css_properties['-ms-' + prop] = 1
|
81
|
+
@@unitless_css_properties['-moz-' + prop] = 1
|
82
|
+
@@unitless_css_properties['-o-' + prop] = 1
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
unless given_renderer
|
87
|
+
put('', { '@keyframes fadein' => { from: { opacity: 0 }, to: { opacity: 1 }},
|
88
|
+
'.fade_in' => { animation: 'fadein .4s linear' }})
|
89
|
+
put('', { '@keyframes fadeout' => { from: { opacity: 1 }, to: { opacity: 0 }},
|
90
|
+
'.fade_out' => { animation: 'fadeout .3s linear', 'animation-fill-mode' => 'forwards' }})
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def decl(key, value)
|
95
|
+
key = kebab(key)
|
96
|
+
|
97
|
+
if value.is_a?(Numeric) && !@@unitless_css_properties.key?(key)
|
98
|
+
"#{key}:#{value}px;"
|
99
|
+
else
|
100
|
+
"#{key}:#{value};"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def hash(obj)
|
105
|
+
hash_str(JSON.dump(obj))
|
106
|
+
end
|
107
|
+
|
108
|
+
def hash_str(str)
|
109
|
+
h = 5381
|
110
|
+
str.each_codepoint do |cp|
|
111
|
+
h = (h * 33) ^ cp
|
112
|
+
end
|
113
|
+
'_' + h.abs.to_s(36)
|
114
|
+
end
|
115
|
+
|
116
|
+
def kebab(prop)
|
117
|
+
prop.to_s.gsub(KEBAB_REGEX, '-$&').downcase.to_sym
|
118
|
+
end
|
119
|
+
|
120
|
+
def put(css_selector, decls, atrule = nil)
|
121
|
+
return if @client && !@renderer[:hydrate_force_put] && @hydrated.key?(css_selector)
|
122
|
+
|
123
|
+
str = ''
|
124
|
+
postponed = []
|
125
|
+
|
126
|
+
decls.each do |prop, value|
|
127
|
+
if value.is_a?(Hash) && !value.is_a?(Array)
|
128
|
+
postponed.push(prop)
|
129
|
+
else
|
130
|
+
str += decl(prop, value)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
unless str.empty?
|
135
|
+
str = css_selector + '{' + str + '}'
|
136
|
+
put_raw(atrule ? atrule + '{' + str + '}' : str)
|
137
|
+
end
|
138
|
+
|
139
|
+
postponed.each do |prop|
|
140
|
+
if prop[0] === '@' && prop != '@font-face'
|
141
|
+
put_at(css_selector, decls[prop], prop)
|
142
|
+
else
|
143
|
+
put(selector(css_selector, prop), decls[prop], atrule)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def put_at(_, keyframes, prelude)
|
149
|
+
if prelude[1] == 'k'
|
150
|
+
str = ''
|
151
|
+
keyframes.each do |keyframe, decls|
|
152
|
+
str_decls = ''
|
153
|
+
decls.each do |prop, value|
|
154
|
+
str_decls += decl(prop, value)
|
155
|
+
end
|
156
|
+
str += "#{keyframe}{#{str_decls}}"
|
157
|
+
end
|
158
|
+
|
159
|
+
@renderer[:prefixes].each do |prefix|
|
160
|
+
raw_key_frames = prelude.sub('@keyframes', "@#{prefix}keyframes") + "{#{str}}"
|
161
|
+
if @client
|
162
|
+
ksh = @renderer[:ksh]
|
163
|
+
`ksh.appendChild(document.createTextNode(raw_key_frames))`
|
164
|
+
else
|
165
|
+
put_raw(raw_key_frames)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
return
|
170
|
+
end
|
171
|
+
put(nil, keyframes, prelude)
|
172
|
+
end
|
173
|
+
|
174
|
+
def put_raw(raw_css_rule)
|
175
|
+
@client ? put_raw_client(raw_css_rule) : put_raw_ssr(raw_css_rule)
|
176
|
+
end
|
177
|
+
|
178
|
+
def put_raw_ssr(raw_css_rule)
|
179
|
+
@renderer[:raw] << raw_css_rule
|
180
|
+
end
|
181
|
+
|
182
|
+
def put_raw_client(raw_css_rule)
|
183
|
+
# .insertRule() is faster than .appendChild(), that's why we use it in PROD.
|
184
|
+
# But CSS injected using .insertRule() is not displayed in Chrome Devtools
|
185
|
+
sheet = @renderer[:sh].JS[:sheet]
|
186
|
+
# Unknown pseudo-selectors will throw, this try/catch swallows all errors.
|
187
|
+
`sheet.insertRule(raw_css_rule, sheet.cssRules.length)` rescue nil
|
188
|
+
end
|
127
189
|
|
128
190
|
# addons
|
129
191
|
|
130
|
-
|
131
|
-
self.rule = function (renderer) {
|
132
|
-
if (in_dev) {
|
133
|
-
renderer.rule_blocks = {};
|
134
|
-
}
|
192
|
+
# rule
|
135
193
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
}
|
141
|
-
}
|
194
|
+
def rule(css, block = nil)
|
195
|
+
block = block || hash(css)
|
196
|
+
block = @renderer[:pfx] + block
|
197
|
+
put('.' + block, css)
|
142
198
|
|
143
|
-
|
144
|
-
|
145
|
-
if (in_dev) {
|
146
|
-
if (block) {
|
147
|
-
if (typeof block !== 'string') {
|
148
|
-
throw new TypeError(
|
149
|
-
'nano-css block name must be a string. ' +
|
150
|
-
'For example, use nano.rule({color: "red"}, "RedText").'
|
151
|
-
);
|
152
|
-
}
|
153
|
-
|
154
|
-
if (renderer.rule_blocks[block]) {
|
155
|
-
console.error('nano-css block name "' + block + '" used more than once.');
|
156
|
-
}
|
157
|
-
|
158
|
-
renderer.rule_blocks[block] = 1;
|
159
|
-
}
|
160
|
-
}
|
199
|
+
' ' + block
|
200
|
+
end
|
161
201
|
|
162
|
-
|
163
|
-
block = renderer.pfx + block;
|
164
|
-
renderer.put('.' + block, css);
|
165
|
-
|
166
|
-
return ' ' + block;
|
167
|
-
};
|
168
|
-
};
|
169
|
-
}
|
170
|
-
|
171
|
-
%x{
|
172
|
-
self.sheet = function (renderer) {
|
173
|
-
renderer.delete_from_sheet = function(rule_name) {
|
174
|
-
let selector_rule_name = "._" + rule_name + "-";
|
175
|
-
if (renderer.sh && renderer.sh.sheet) {
|
176
|
-
let sheet = renderer.sh.sheet;
|
177
|
-
let rules = sheet.cssRules;
|
178
|
-
for (let i=rules.length-1;i>=0;i--) {
|
179
|
-
let rule = rules.item(i);
|
180
|
-
if (rule.cssText.includes(selector_rule_name)) {
|
181
|
-
sheet.deleteRule(i);
|
182
|
-
}
|
183
|
-
}
|
184
|
-
}
|
185
|
-
}
|
202
|
+
# sheet
|
186
203
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
if (in_dev && renderer.sourcemaps) {
|
198
|
-
// In dev mode emit CSS immediately to generate sourcemaps.
|
199
|
-
result[elementModifier] = renderer.rule(styles, block + '-' + elementModifier);
|
200
|
-
} else {
|
201
|
-
Object.defineProperty(result, elementModifier, {
|
202
|
-
configurable: true,
|
203
|
-
enumerable: true,
|
204
|
-
get: function () {
|
205
|
-
var classNames = renderer.rule(styles, block + '-' + elementModifier);
|
206
|
-
|
207
|
-
Object.defineProperty(result, elementModifier, {
|
208
|
-
value: classNames,
|
209
|
-
enumerable: true
|
210
|
-
});
|
211
|
-
|
212
|
-
return classNames;
|
213
|
-
},
|
214
|
-
});
|
215
|
-
}
|
216
|
-
};
|
217
|
-
|
218
|
-
for (var elementModifier in map) {
|
219
|
-
onElementModifier(elementModifier);
|
220
|
-
}
|
221
|
-
|
222
|
-
return result;
|
223
|
-
};
|
224
|
-
};
|
225
|
-
}
|
226
|
-
|
227
|
-
%x{
|
228
|
-
self.nesting = function (renderer) {
|
229
|
-
renderer.selector = function (parentSelectors, selector) {
|
230
|
-
var parents = parentSelectors.split(',');
|
231
|
-
var result = [];
|
232
|
-
var selectors = selector.split(',');
|
233
|
-
var len1 = parents.length;
|
234
|
-
var len2 = selectors.length;
|
235
|
-
var i, j, sel, pos, parent, replacedSelector;
|
236
|
-
|
237
|
-
for (i = 0; i < len2; i++) {
|
238
|
-
sel = selectors[i];
|
239
|
-
pos = sel.indexOf('&');
|
240
|
-
|
241
|
-
if (pos > -1) {
|
242
|
-
for (j = 0; j < len1; j++) {
|
243
|
-
parent = parents[j];
|
244
|
-
replacedSelector = sel.replace(/&/g, parent);
|
245
|
-
result.push(replacedSelector);
|
246
|
-
}
|
247
|
-
} else {
|
248
|
-
for (j = 0; j < len1; j++) {
|
249
|
-
parent = parents[j];
|
250
|
-
|
251
|
-
if (parent) {
|
252
|
-
result.push(parent + ' ' + sel);
|
253
|
-
} else {
|
254
|
-
result.push(sel);
|
255
|
-
}
|
256
|
-
}
|
204
|
+
def delete_from_sheet(rule_name)
|
205
|
+
selector_rule_name = "._" + rule_name + "-"
|
206
|
+
if renderer[:sh] && renderer[:sh].JS[:sheet]
|
207
|
+
sheet = renderer[:sh].JS[:sheet]
|
208
|
+
css_rules = sheet.JS[:cssRules]
|
209
|
+
%x{
|
210
|
+
let i = 0;
|
211
|
+
for(i=0; i<css_rules.length; i++) {
|
212
|
+
if (css_rules[i].cssText.includes(selector_rule_name)) {
|
213
|
+
sheet.deleteRule(i);
|
257
214
|
}
|
258
215
|
}
|
259
|
-
|
260
|
-
return result.join(',');
|
261
|
-
};
|
262
|
-
};
|
263
|
-
}
|
264
|
-
|
265
|
-
%x{
|
266
|
-
self.hydrate = function (renderer) {
|
267
|
-
var hydrated = {};
|
268
|
-
renderer.hydrate_force_put = false;
|
269
|
-
renderer.hydrate = function (sh) {
|
270
|
-
var cssRules = sh.cssRules || sh.sheet.cssRules;
|
271
|
-
|
272
|
-
for (var i = 0; i < cssRules.length; i++)
|
273
|
-
hydrated[cssRules[i].selectorText] = 1;
|
274
|
-
};
|
275
|
-
|
276
|
-
if (renderer.client) {
|
277
|
-
if (renderer.sh) renderer.hydrate(renderer.sh);
|
278
|
-
|
279
|
-
var put = renderer.put;
|
280
|
-
|
281
|
-
renderer.put = function (selector, css) {
|
282
|
-
if (!renderer.hydrate_force_put && selector in hydrated) return;
|
283
|
-
|
284
|
-
put(selector, css);
|
285
|
-
};
|
286
216
|
}
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
'
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
self.unitless = function (renderer) {
|
350
|
-
var decl = renderer.decl;
|
351
|
-
|
352
|
-
renderer.decl = function (prop, value) {
|
353
|
-
var str = decl(prop, value);
|
354
|
-
|
355
|
-
if (typeof value === 'number') {
|
356
|
-
var pos = str.indexOf(':');
|
357
|
-
var propKebab = str.substr(0, pos);
|
358
|
-
|
359
|
-
if (!unitlessCssProperties[propKebab]) {
|
360
|
-
return decl(prop, value + 'px');
|
361
|
-
}
|
362
|
-
}
|
363
|
-
|
364
|
-
return str;
|
365
|
-
};
|
366
|
-
};
|
367
|
-
}
|
368
|
-
|
369
|
-
%x{
|
370
|
-
self.global = function (renderer) {
|
371
|
-
var selector = renderer.selector;
|
372
|
-
|
373
|
-
renderer.selector = function (parent, current) {
|
374
|
-
if (parent.indexOf(':global') > -1) parent = '';
|
375
|
-
|
376
|
-
return selector(parent, current);
|
377
|
-
};
|
378
|
-
|
379
|
-
renderer.global = function (css) {
|
380
|
-
return renderer.put('', css);
|
381
|
-
};
|
382
|
-
};
|
383
|
-
}
|
384
|
-
|
385
|
-
%x{
|
386
|
-
self.keyframes = function (renderer, config) {
|
387
|
-
config = renderer.assign({
|
388
|
-
prefixes: ['-webkit-', '-moz-', '-o-', ''],
|
389
|
-
}, config || {});
|
390
|
-
|
391
|
-
var prefixes = config.prefixes;
|
392
|
-
|
393
|
-
if (renderer.client) {
|
394
|
-
// Craete @keyframe Stylesheet `ksh`.
|
395
|
-
document.head.appendChild(renderer.ksh = document.createElement('style'));
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
def on_element_modifier(element_modifier, map, block, result)
|
221
|
+
result[element_modifier] = rule(map[element_modifier], "#{block}-#{element_modifier}")
|
222
|
+
end
|
223
|
+
|
224
|
+
def sheet(map, block = nil)
|
225
|
+
result = {}
|
226
|
+
block = hash(map) unless block
|
227
|
+
map.each_key do |element_modifier|
|
228
|
+
on_element_modifier(element_modifier, map, block, result)
|
229
|
+
end
|
230
|
+
result
|
231
|
+
end
|
232
|
+
|
233
|
+
# nesting
|
234
|
+
|
235
|
+
def selector(parent_selectors, css_selector)
|
236
|
+
parent_selectors = '' if parent_selectors.include?(':global')
|
237
|
+
parents = parent_selectors.split(',')
|
238
|
+
selectors = css_selector.split(',')
|
239
|
+
result = []
|
240
|
+
|
241
|
+
selectors.each do |sel|
|
242
|
+
pos = sel.index('&')
|
243
|
+
|
244
|
+
if pos
|
245
|
+
if parents.empty?
|
246
|
+
replaced_selector = sel.gsub(/&/, parent)
|
247
|
+
result.push(replaced_selector)
|
248
|
+
else
|
249
|
+
parents.each do |parent|
|
250
|
+
replaced_selector = sel.gsub(/&/, parent)
|
251
|
+
result.push(replaced_selector)
|
252
|
+
end
|
253
|
+
end
|
254
|
+
else
|
255
|
+
if parents.empty?
|
256
|
+
result.push(sel)
|
257
|
+
else
|
258
|
+
parents.each do |parent|
|
259
|
+
result.push(parent + ' ' + sel)
|
260
|
+
end
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
return result.join(',')
|
266
|
+
end
|
267
|
+
|
268
|
+
# hydrate
|
269
|
+
|
270
|
+
def hydrate(sh)
|
271
|
+
css_rules = sh.JS[:cssRules] || sh.JS[:sheet].JS[:cssRules]
|
272
|
+
|
273
|
+
%x{
|
274
|
+
let i = 0;
|
275
|
+
let st;
|
276
|
+
for(i=0; i<css_rules.length; i++) {
|
277
|
+
st = css_rules[i].selectorText;
|
278
|
+
if (st) { #{@hydrated[`st`] = 1}; }
|
396
279
|
}
|
280
|
+
}
|
281
|
+
end
|
397
282
|
|
398
|
-
var putAt = renderer.putAt;
|
399
|
-
|
400
|
-
renderer.putAt = function (__, keyframes, prelude) {
|
401
|
-
// @keyframes
|
402
|
-
if (prelude[1] === 'k') {
|
403
|
-
var str = '';
|
404
|
-
|
405
|
-
for (var keyframe in keyframes) {
|
406
|
-
var decls = keyframes[keyframe];
|
407
|
-
var strDecls = '';
|
408
|
-
|
409
|
-
for (var prop in decls)
|
410
|
-
strDecls += renderer.decl(prop, decls[prop]);
|
411
|
-
|
412
|
-
str += keyframe + '{' + strDecls + '}';
|
413
|
-
}
|
414
|
-
|
415
|
-
for (var i = 0; i < prefixes.length; i++) {
|
416
|
-
var prefix = prefixes[i];
|
417
|
-
var rawKeyframes = prelude.replace('@keyframes', '@' + prefix + 'keyframes') + '{' + str + '}';
|
418
|
-
|
419
|
-
if (renderer.client) {
|
420
|
-
renderer.ksh.appendChild(document.createTextNode(rawKeyframes));
|
421
|
-
} else {
|
422
|
-
renderer.putRaw(rawKeyframes);
|
423
|
-
}
|
424
|
-
}
|
425
283
|
|
426
|
-
|
427
|
-
}
|
284
|
+
# global
|
428
285
|
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
renderer.keyframes = function (keyframes, block) {
|
433
|
-
if (!block) block = renderer.hash(keyframes);
|
434
|
-
block = renderer.pfx + block;
|
435
|
-
|
436
|
-
renderer.putAt('', keyframes, '@keyframes ' + block);
|
437
|
-
|
438
|
-
return block;
|
439
|
-
};
|
440
|
-
};
|
441
|
-
}
|
442
|
-
|
443
|
-
%x{
|
444
|
-
self.fadeIn = function (renderer) {
|
445
|
-
renderer.put('', {
|
446
|
-
'@keyframes fadeIn': {
|
447
|
-
from: {
|
448
|
-
opacity: 0,
|
449
|
-
},
|
450
|
-
to: {
|
451
|
-
opacity: 1,
|
452
|
-
}
|
453
|
-
},
|
286
|
+
def global(css)
|
287
|
+
put('', css)
|
288
|
+
end
|
454
289
|
|
455
|
-
|
456
|
-
animation: 'fadeIn .4s linear',
|
457
|
-
}
|
458
|
-
});
|
459
|
-
};
|
460
|
-
}
|
461
|
-
|
462
|
-
%x{
|
463
|
-
self.fadeOut = function (renderer) {
|
464
|
-
renderer.put('', {
|
465
|
-
'@keyframes fadeOut': {
|
466
|
-
from: {
|
467
|
-
opacity: 1,
|
468
|
-
},
|
469
|
-
to: {
|
470
|
-
opacity: 0,
|
471
|
-
}
|
472
|
-
},
|
290
|
+
# keyframes
|
473
291
|
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
end
|
292
|
+
def keyframes(keyframes, cblock = nil)
|
293
|
+
block = hash(keyframes) unless block
|
294
|
+
block = @renderer[:pfx] + block
|
295
|
+
put_at('', keyframes, '@keyframes' + block)
|
296
|
+
block
|
297
|
+
end
|
298
|
+
end
|