lilact 0.0.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 (164) hide show
  1. package/Icon/r +0 -0
  2. package/LICENSE.TXT +26 -0
  3. package/README.md +116 -0
  4. package/bin/copy-demo.js +26 -0
  5. package/bin/transpile-dir.js +112 -0
  6. package/bin/transpile.js +137 -0
  7. package/dist/lilact.development.js +9344 -0
  8. package/dist/lilact.development.js.map +1 -0
  9. package/dist/lilact.production.min.js +63 -0
  10. package/dist/lilact.production.min.js.map +1 -0
  11. package/docs/.nojekyll +1 -0
  12. package/docs/assets/hierarchy.js +1 -0
  13. package/docs/assets/highlight.css +71 -0
  14. package/docs/assets/icons.js +18 -0
  15. package/docs/assets/icons.svg +1 -0
  16. package/docs/assets/main.js +60 -0
  17. package/docs/assets/navigation.js +1 -0
  18. package/docs/assets/search.js +1 -0
  19. package/docs/assets/style.css +1633 -0
  20. package/docs/classes/accessories.ErrorBoundary.html +37 -0
  21. package/docs/classes/accessories.Suspense.html +41 -0
  22. package/docs/classes/components.Component.html +45 -0
  23. package/docs/classes/components.HTMLComponent.html +32 -0
  24. package/docs/classes/components.RootComponent.html +32 -0
  25. package/docs/classes/transition.Transition.html +31 -0
  26. package/docs/functions/accessories.Spinner.html +9 -0
  27. package/docs/functions/components.createComponent.html +8 -0
  28. package/docs/functions/components.createRoot.html +5 -0
  29. package/docs/functions/components.render.html +5 -0
  30. package/docs/functions/hooks.createContext.html +3 -0
  31. package/docs/functions/hooks.useActionState.html +3 -0
  32. package/docs/functions/hooks.useCallback.html +5 -0
  33. package/docs/functions/hooks.useContext.html +3 -0
  34. package/docs/functions/hooks.useDeferredValue.html +4 -0
  35. package/docs/functions/hooks.useEffect.html +3 -0
  36. package/docs/functions/hooks.useHook.html +5 -0
  37. package/docs/functions/hooks.useId.html +4 -0
  38. package/docs/functions/hooks.useLayoutEffect.html +3 -0
  39. package/docs/functions/hooks.useLocalStorage.html +4 -0
  40. package/docs/functions/hooks.useMemo.html +4 -0
  41. package/docs/functions/hooks.useReducer.html +6 -0
  42. package/docs/functions/hooks.useRef.html +4 -0
  43. package/docs/functions/hooks.useState.html +3 -0
  44. package/docs/functions/hooks.useTransition.html +3 -0
  45. package/docs/functions/jsx.transpileJSX.html +6 -0
  46. package/docs/functions/misc.Fragment.html +3 -0
  47. package/docs/functions/misc.classNames.html +2 -0
  48. package/docs/functions/misc.deepEqual.html +3 -0
  49. package/docs/functions/misc.findDOMNode.html +3 -0
  50. package/docs/functions/misc.getComponentByPointer.html +3 -0
  51. package/docs/functions/misc.isAsync.html +3 -0
  52. package/docs/functions/misc.isClass.html +3 -0
  53. package/docs/functions/misc.isEmpty.html +3 -0
  54. package/docs/functions/misc.isError.html +3 -0
  55. package/docs/functions/misc.isThenable.html +3 -0
  56. package/docs/functions/misc.isValidElement.html +3 -0
  57. package/docs/functions/misc.shallowEqual.html +3 -0
  58. package/docs/functions/redux.Provider.html +5 -0
  59. package/docs/functions/redux.connect.html +5 -0
  60. package/docs/functions/redux.useDispatch.html +3 -0
  61. package/docs/functions/redux.useSelector.html +5 -0
  62. package/docs/functions/redux.useStore.html +3 -0
  63. package/docs/functions/router.HashRouter.html +5 -0
  64. package/docs/functions/router.Link.html +12 -0
  65. package/docs/functions/router.NavLink.html +10 -0
  66. package/docs/functions/router.Route.html +6 -0
  67. package/docs/functions/router.Routes.html +4 -0
  68. package/docs/functions/router.useLocation.html +3 -0
  69. package/docs/functions/router.useNavigate.html +3 -0
  70. package/docs/functions/run.require.html +14 -0
  71. package/docs/functions/run.run.html +13 -0
  72. package/docs/functions/run.runScripts.html +7 -0
  73. package/docs/functions/run.traceError.html +6 -0
  74. package/docs/functions/timers.animationFramePromise.html +3 -0
  75. package/docs/functions/timers.clearInterval.html +2 -0
  76. package/docs/functions/timers.clearTimeout.html +2 -0
  77. package/docs/functions/timers.grabTimers.html +3 -0
  78. package/docs/functions/timers.pauseTimers.html +2 -0
  79. package/docs/functions/timers.releaseTimers.html +2 -0
  80. package/docs/functions/timers.resetTimers.html +2 -0
  81. package/docs/functions/timers.resumeTimers.html +2 -0
  82. package/docs/functions/timers.setInterval.html +5 -0
  83. package/docs/functions/timers.setTimeout.html +4 -0
  84. package/docs/functions/timers.timeoutPromise.html +4 -0
  85. package/docs/functions/transition.CSSTransition.html +18 -0
  86. package/docs/functions/transition.TransitionGroup.html +5 -0
  87. package/docs/hierarchy.html +1 -0
  88. package/docs/index.html +88 -0
  89. package/docs/media/icon.png +0 -0
  90. package/docs/modules/accessories.html +1 -0
  91. package/docs/modules/components.html +1 -0
  92. package/docs/modules/hooks.html +1 -0
  93. package/docs/modules/jsx.html +1 -0
  94. package/docs/modules/misc.html +1 -0
  95. package/docs/modules/redux.html +1 -0
  96. package/docs/modules/router.html +1 -0
  97. package/docs/modules/run.html +1 -0
  98. package/docs/modules/timers.html +1 -0
  99. package/docs/modules/transition.html +1 -0
  100. package/docs/modules.html +1 -0
  101. package/docs/static/demos/actionstate.jsx +41 -0
  102. package/docs/static/demos/boundary.jsx +52 -0
  103. package/docs/static/demos/context.jsx +68 -0
  104. package/docs/static/demos/css-transition.jsx +65 -0
  105. package/docs/static/demos/modal.jsx +41 -0
  106. package/docs/static/demos/proptypes.jsx +37 -0
  107. package/docs/static/demos/reducer.jsx +71 -0
  108. package/docs/static/demos/redux.jsx +58 -0
  109. package/docs/static/demos/router.jsx +153 -0
  110. package/docs/static/demos/stopwatch.jsx +42 -0
  111. package/docs/static/demos/suspense.jsx +48 -0
  112. package/docs/static/demos/transition.jsx +40 -0
  113. package/docs/static/demos/use-differed.jsx +30 -0
  114. package/docs/static/demos/usetransition.jsx +37 -0
  115. package/docs/static/index.html +212 -0
  116. package/docs/static/lilact.development.js +9344 -0
  117. package/docs/static/lilact.production.min.js +63 -0
  118. package/docs/static/prismjs/LICENSE.md +21 -0
  119. package/docs/static/prismjs/prism-jsx.min.js +1 -0
  120. package/docs/static/prismjs/prism.min.css +1 -0
  121. package/docs/static/prismjs/prism.min.js +16 -0
  122. package/docs/variables/jsx.transpilerConfig.html +1 -0
  123. package/docs/variables/misc.Children.html +10 -0
  124. package/icon.png +0 -0
  125. package/package.json +39 -0
  126. package/root/demos/actionstate.jsx +41 -0
  127. package/root/demos/boundary.jsx +52 -0
  128. package/root/demos/context.jsx +68 -0
  129. package/root/demos/css-transition.jsx +65 -0
  130. package/root/demos/modal.jsx +41 -0
  131. package/root/demos/proptypes.jsx +37 -0
  132. package/root/demos/reducer.jsx +71 -0
  133. package/root/demos/redux.jsx +58 -0
  134. package/root/demos/router.jsx +153 -0
  135. package/root/demos/stopwatch.jsx +42 -0
  136. package/root/demos/suspense.jsx +48 -0
  137. package/root/demos/transition.jsx +40 -0
  138. package/root/demos/use-differed.jsx +30 -0
  139. package/root/demos/usetransition.jsx +37 -0
  140. package/root/index.html +212 -0
  141. package/root/lilact.development.js +9344 -0
  142. package/root/lilact.production.min.js +63 -0
  143. package/root/prismjs/LICENSE.md +21 -0
  144. package/root/prismjs/prism-jsx.min.js +1 -0
  145. package/root/prismjs/prism.min.css +1 -0
  146. package/root/prismjs/prism.min.js +16 -0
  147. package/src/accessories.jsx +287 -0
  148. package/src/components.jsx +1063 -0
  149. package/src/events.jsx +175 -0
  150. package/src/hooks.jsx +461 -0
  151. package/src/jsx.addons.js +70 -0
  152. package/src/jsx.js +1168 -0
  153. package/src/lilact.jsx +115 -0
  154. package/src/loader.cjs +59 -0
  155. package/src/misc.jsx +419 -0
  156. package/src/redux.jsx +198 -0
  157. package/src/router.jsx +282 -0
  158. package/src/run.jsx +275 -0
  159. package/src/timers.jsx +313 -0
  160. package/src/transition.jsx +244 -0
  161. package/src/vlq.js +94 -0
  162. package/tsconfig.json +15 -0
  163. package/typedoc.json +23 -0
  164. package/webpack.config.js +196 -0
@@ -0,0 +1,244 @@
1
+ /*
2
+
3
+ Lilact
4
+ Copyright (C) 2024-2026 Arash Kazemi <contact.arash.kazemi@gmail.com>
5
+ All rights reserved.
6
+
7
+ BSD-2-Clause
8
+
9
+ Redistribution and use in source and binary forms, with or without
10
+ modification, are permitted provided that the following conditions are met:
11
+
12
+ * Redistributions of source code must retain the above copyright
13
+ notice, this list of conditions and the following disclaimer.
14
+ * Redistributions in binary form must reproduce the above copyright
15
+ notice, this list of conditions and the following disclaimer in the
16
+ documentation and/or other materials provided with the distribution.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21
+ ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
22
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+
29
+ */
30
+
31
+ ʔ defineSymbols ( "LILACT", [ "CORE", "COMPONENT", "CHILD_CLASS_ADDENDUM" ] ) ʔ
32
+
33
+ /* States */
34
+ const UNMOUNTED = "unmounted";
35
+ const EXITED = "exited";
36
+ const ENTERING = "entering";
37
+ const ENTERED = "entered";
38
+ const EXITING = "exiting";
39
+
40
+ import {setTimeout, clearTimeout} from "./timers.jsx"
41
+ import {Children} from "./misc.jsx"
42
+ import {useEffect} from "./hooks.jsx"
43
+
44
+ /**
45
+ * Transition component that manages enter/exit lifecycle and calls callbacks based on state changes.
46
+ *
47
+ * @param props - Component props.
48
+ * @param props.in - Boolean/flag indicating whether the component should be entered/shown.
49
+ * @param [props.timeout=defaultTransitionTimeout] - Duration (or durations) for the transition.
50
+ * @param [props.mountOnEnter=false] - If true, mount the child only when entering.
51
+ * @param [props.unmountOnExit=false] - If true, unmount the child after exiting.
52
+ * @param [props.appear=false] - If true, run the enter transition on initial mount.
53
+ * @param props.onEnter - Called when entering begins.
54
+ * @param props.onEntering - Called while the component is entering.
55
+ * @param props.onEntered - Called when entering completes.
56
+ * @param props.onExit - Called when exiting begins.
57
+ * @param props.onExiting - Called while the component is exiting.
58
+ * @param props.onExited - Called when exiting completes.
59
+ * @param props.children - Render prop receiving transition state/props.
60
+ */
61
+ export function Transition({
62
+ in: inProp,
63
+ timeout = Lilact.defaultTransitionTimeout,
64
+ mountOnEnter = false,
65
+ unmountOnExit = false,
66
+ appear = false,
67
+ onEnter,
68
+ onEntering,
69
+ onEntered,
70
+ onExit,
71
+ onExiting,
72
+ onExited,
73
+ children,
74
+
75
+ // this is underscored to prevent accidental setting by the user.
76
+ // i added it to the Transition itself to simplify the implementation,
77
+ // but the user should use CSSTransition itself.
78
+ _classNames: classNames
79
+ }) {
80
+ this[CORE].is_mounted ??= !mountOnEnter || inProp || appear;
81
+ this[CORE].is_appeared ??= inProp;
82
+ this[CORE].timer ??= null;
83
+
84
+ if(!this.state) {
85
+ if (!this[CORE].is_mounted) this.state = UNMOUNTED;
86
+ if (inProp) {
87
+ this.state = appear && !this[CORE].is_appeared ? ENTERING : ENTERED;
88
+ }
89
+ this.state = EXITED;
90
+ }
91
+
92
+ useEffect(() => {
93
+ return () => clearTimeout(this[CORE].timer);
94
+ }, []);
95
+
96
+ useEffect(() => {
97
+ if (!this[CORE].is_appeared && appear && this.state === ENTERING && inProp) {
98
+ onEnter?.();
99
+ requestAnimationFrame(() => {
100
+ onEntering?.(!this[CORE].is_appeared);
101
+ clearTimeout(this[CORE].timer);
102
+ this[CORE].timer = setTimeout(() => {
103
+ this.setState(ENTERED);
104
+ this[CORE].is_appeared = true;
105
+ onEntered?.(!this[CORE].is_appeared);
106
+ }, timeout);
107
+ });
108
+ }
109
+ }, []);
110
+
111
+ useEffect(() => {
112
+ if (inProp) {
113
+ this[CORE].is_mounted = true;
114
+ // If we are already entering/entered, no-op
115
+ if (this.state === ENTERING || this.state === ENTERED) return;
116
+
117
+ onEnter?.(!this[CORE].is_appeared);
118
+ this.setState(ENTERING, () => {
119
+ onEntering?.(!this[CORE].is_appeared);
120
+ clearTimeout(this[CORE].timer);
121
+ this[CORE].timer = setTimeout(() => {
122
+ this.setState(ENTERED);
123
+ this[CORE].is_appeared = true;
124
+ onEntered?.();
125
+ }, timeout);
126
+ });
127
+ }
128
+ else {
129
+ if (this.state === UNMOUNTED || this.state === EXITING || this.state === EXITED) return;
130
+
131
+ onExit?.();
132
+ this.setState(EXITING, () => {
133
+ onExiting?.();
134
+ clearTimeout(this[CORE].timer);
135
+ this[CORE].timer = setTimeout(() => {
136
+ this.setState(EXITED);
137
+ onExited?.();
138
+ if (unmountOnExit) {
139
+ this[CORE].is_mounted = false;
140
+ this.setState(UNMOUNTED);
141
+ }
142
+ }, timeout);
143
+ });
144
+ }
145
+ }, [inProp, timeout]);
146
+
147
+ if (!this[CORE].is_mounted) return null;
148
+
149
+ if(classNames) {
150
+ if (this.state === ENTERING) {
151
+ if(this[CORE].is_appeared)
152
+ this[CORE][CHILD_CLASS_ADDENDUM] = classNames.appearActive;
153
+ else
154
+ this[CORE][CHILD_CLASS_ADDENDUM] = classNames.enterActive;
155
+ }
156
+ else if (this.state === ENTERED) {
157
+ if(this[CORE].is_appeared)
158
+ this[CORE][CHILD_CLASS_ADDENDUM] = classNames.appearDone;
159
+ else
160
+ this[CORE][CHILD_CLASS_ADDENDUM] = classNames.enterDone;
161
+ }
162
+ else if (this.state === EXITING) this[CORE][CHILD_CLASS_ADDENDUM] = classNames.exitActive;
163
+ else if (this.state === EXITED) this[CORE][CHILD_CLASS_ADDENDUM] = classNames.exitDone;
164
+ }
165
+ return children;
166
+ }
167
+
168
+
169
+ /**
170
+ * CSSTransition component that extends Transition by applying CSS class names during enter/exit phases.
171
+ *
172
+ * Lilact accepts multiple children for CSSTransition. This has the benefit
173
+ * of receiving single events on multiple animated components.
174
+ *
175
+ * @param props - Component props.
176
+ * @param props.in - Boolean/flag indicating whether the component should be entered/shown.
177
+ * @param [props.timeout=defaultTransitionTimeout] - Duration (or durations) for the transition.
178
+ * @param [props.classNames="fade"] - Base CSS class name(s) used for the transition states.
179
+ * @param [props.mountOnEnter=false] - If true, mount the child only when entering.
180
+ * @param [props.unmountOnExit=false] - If true, unmount the child after exiting.
181
+ * @param [props.appear=false] - If true, run the enter transition on initial mount.
182
+ * @param props.children - Render prop receiving transition state/props.
183
+ * @param props.onEnter - Called when entering begins.
184
+ * @param props.onEntering - Called while the component is entering.
185
+ * @param props.onEntered - Called when entering completes.
186
+ * @param props.onExit - Called when exiting begins.
187
+ * @param props.onExiting - Called while the component is exiting.
188
+ * @param props.onExited - Called when exiting completes.
189
+ */
190
+ export function CSSTransition({
191
+ in: inProp,
192
+ timeout = defaultTransitionTimeout,
193
+ classNames = "fade",
194
+ mountOnEnter = false,
195
+ unmountOnExit = false,
196
+ appear = false,
197
+ children,
198
+ onEnter, onEntering, onEntered,
199
+ onExit, onExiting, onExited,
200
+ }) {
201
+
202
+ if(typeof(classNames)==='string') {
203
+ classNames = {
204
+ appear: `${classNames}-enter ${classNames}-appear`,
205
+ appearActive: `${classNames}-enter-active ${classNames}-appear-active`,
206
+ appearDone: `${classNames}-enter-done ${classNames}-appear-done`,
207
+ enter: `${classNames}-enter`,
208
+ enterActive: `${classNames}-enter-active`,
209
+ enterDone: `${classNames}-enter-done`,
210
+ exit: `${classNames}-exit`,
211
+ exitActive: `${classNames}-exit-active`,
212
+ exitDone: `${classNames}-exit-done`,
213
+ };
214
+ }
215
+ return (
216
+ <Transition
217
+ in={inProp}
218
+ timeout={timeout}
219
+ mountOnEnter={mountOnEnter}
220
+ unmountOnExit={unmountOnExit}
221
+ appear={appear}
222
+ onEnter={onEnter}
223
+ onEntering={onEntering}
224
+ onEntered={onEntered}
225
+ onExit={onExit}
226
+ onExiting={onExiting}
227
+ onExited={onExited}
228
+ _classNames={classNames}
229
+ >
230
+ {children}
231
+ </Transition>
232
+ );
233
+ }
234
+
235
+ /**
236
+ * Lilact doesn't need TransitionGroup, so it is the same as a fragment.
237
+ * In Lilact all the transitions and timeouts are automatically grouped.
238
+ *
239
+ * The only missing feature here is the childFactory. I may add it in
240
+ * the future, but there are simple workarounds for that.
241
+ */
242
+ export function TransitionGroup({ children }) {
243
+ return children;
244
+ }
package/src/vlq.js ADDED
@@ -0,0 +1,94 @@
1
+ // Fork of https://github.com/Rich-Harris/vlq
2
+ // Adapted from murzwin.com/base64vlq.html by Alexander Pavlov.
3
+ // License: MIT
4
+
5
+ /** @type {Record<string, number>} */
6
+ let char_to_integer = {};
7
+
8
+ /** @type {Record<number, string>} */
9
+ let integer_to_char = {};
10
+
11
+ 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
12
+ .split('')
13
+ .forEach(function (char, i) {
14
+ char_to_integer[char] = i;
15
+ integer_to_char[i] = char;
16
+ });
17
+
18
+ /** @param {string} string */
19
+ export function decode(string) {
20
+ /** @type {number[]} */
21
+ let result = [];
22
+
23
+ let shift = 0;
24
+ let value = 0;
25
+
26
+ for (let i = 0; i < string.length; i += 1) {
27
+ let integer = char_to_integer[string[i]];
28
+
29
+ if (integer === undefined) {
30
+ throw new Error('Invalid character (' + string[i] + ')');
31
+ }
32
+
33
+ const has_continuation_bit = integer & 32;
34
+
35
+ integer &= 31;
36
+ value += integer << shift;
37
+
38
+ if (has_continuation_bit) {
39
+ shift += 5;
40
+ } else {
41
+ const should_negate = value & 1;
42
+ value >>>= 1;
43
+
44
+ if (should_negate) {
45
+ result.push(value === 0 ? -0x80000000 : -value);
46
+ } else {
47
+ result.push(value);
48
+ }
49
+
50
+ // reset
51
+ value = shift = 0;
52
+ }
53
+ }
54
+
55
+ return result;
56
+ }
57
+
58
+ /** @param {number | number[]} value */
59
+ export function encode(...value) {
60
+ if (typeof value === 'number') {
61
+ return encode_integer(value);
62
+ }
63
+
64
+ let result = '';
65
+ for (let i = 0; i < value.length; i += 1) {
66
+ result += encode_integer(value[i]);
67
+ }
68
+
69
+ return result;
70
+ }
71
+
72
+ /** @param {number} num */
73
+ function encode_integer(num) {
74
+ let result = '';
75
+
76
+ if (num < 0) {
77
+ num = (-num << 1) | 1;
78
+ } else {
79
+ num <<= 1;
80
+ }
81
+
82
+ do {
83
+ let clamped = num & 31;
84
+ num >>>= 5;
85
+
86
+ if (num > 0) {
87
+ clamped |= 32;
88
+ }
89
+
90
+ result += integer_to_char[clamped];
91
+ } while (num > 0);
92
+
93
+ return result;
94
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ "allowJs": true,
4
+ "checkJs": false
5
+ },
6
+ "include": [
7
+ ".tmp/**/*.js"
8
+ ],
9
+ "exclude": [
10
+ "**/node_modules",
11
+ "**/dist",
12
+ "**/build",
13
+ "**/src"
14
+ ]
15
+ }
package/typedoc.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "compilerOptions": {
3
+ "allowJs": true,
4
+ "checkJs": false,
5
+ "maxNodeModuleJsDepth": 0,
6
+ "skipLibCheck": true,
7
+ },
8
+ "name": "Lilact",
9
+ "entryPoints": [
10
+ ".tmp/router.js",
11
+ ".tmp/accessories.js",
12
+ ".tmp/components.js",
13
+ // ".tmp/events.js",
14
+ ".tmp/hooks.js",
15
+ ".tmp/misc.js",
16
+ ".tmp/run.js",
17
+ ".tmp/jsx.js",
18
+ ".tmp/redux.js",
19
+ ".tmp/timers.js",
20
+ ".tmp/transition.js",
21
+ // ".tmp/lilact.js"
22
+ ],
23
+ }
@@ -0,0 +1,196 @@
1
+ /*
2
+
3
+ Lilact
4
+ Copyright (C) 2024-2025 Arash Kazemi <contact.arash.kazemi@gmail.com>
5
+ All rights reserved.
6
+
7
+ BSD-2-Clause
8
+
9
+ Redistribution and use in source and binary forms, with or without
10
+ modification, are permitted provided that the following conditions are met:
11
+
12
+ * Redistributions of source code must retain the above copyright
13
+ notice, this list of conditions and the following disclaimer.
14
+ * Redistributions in binary form must reproduce the above copyright
15
+ notice, this list of conditions and the following disclaimer in the
16
+ documentation and/or other materials provided with the distribution.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21
+ ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
22
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+
29
+ */
30
+
31
+ import path from 'path'
32
+
33
+ import { fileURLToPath } from 'url';
34
+ import { dirname, resolve } from 'path';
35
+
36
+ import fs from 'fs';
37
+ import 'webpack';
38
+
39
+
40
+
41
+ export default (env, argv) => {
42
+
43
+ const mode = argv.mode || 'development';
44
+
45
+ const __filename = fileURLToPath(import.meta.url);
46
+ const __dirname = dirname(__filename);
47
+
48
+ const filename = `lilact.${mode}${mode==="development"?"":".min"}.js`;
49
+
50
+ return {
51
+ entry: './src/lilact.jsx',
52
+ mode,
53
+ devtool: 'source-map',
54
+
55
+ optimization: {
56
+ concatenateModules: true, // scope hoisting
57
+ // runtimeChunk: 'single', // centralize runtime helpers
58
+ // splitChunks: {
59
+ // chunks: 'all',
60
+ // cacheGroups: {
61
+ // vendors: {
62
+ // test: /[\\/]node_modules[\\/]/,
63
+ // name: 'vendors',
64
+ // chunks: 'all',
65
+ // },
66
+ // },
67
+ // },
68
+ moduleIds: 'deterministic', // smaller stable ids (or 'hashed')
69
+ minimize: mode === 'production',
70
+ },
71
+ experiments: {
72
+ outputModule: true // enable module output
73
+ },
74
+ ignoreWarnings: [{
75
+ module: /jsx\.js/, // to silent the warning for requiring fs in jsx.js
76
+ message: /Module not found/,
77
+ }],
78
+ output: {
79
+ filename,
80
+ path: path.resolve(__dirname, 'dist'),
81
+ library: { type: 'module' // important: emit an ES module
82
+ },
83
+ },
84
+ resolve: {
85
+ // alias: {
86
+ // "react-is": false,
87
+ // },
88
+ fallback: {
89
+ // buffer: req.resolve('buffer/'),
90
+ }
91
+ },
92
+ module: {
93
+ rules: [{
94
+ test: /\.js$/, // for the preprocessor
95
+ exclude: /node_modules/,
96
+ use: [{
97
+ loader: './src/loader.cjs',
98
+ options: {
99
+ mode
100
+ }
101
+ }]
102
+ },
103
+ {
104
+ test: /\.jsx$/,
105
+ exclude: /node_modules/,
106
+ use: [{
107
+ loader: './src/loader.cjs',
108
+ options: {
109
+ mode
110
+ }
111
+ }]
112
+ }
113
+ ]
114
+ },
115
+ plugins: [{
116
+ apply: (compiler) => {
117
+ compiler.hooks.done.tap('license-plugin', (compilation) => {
118
+ fs.readFile('./dist/' + filename, 'utf8', function(err, jssc) {
119
+
120
+ let out =
121
+ `/*
122
+
123
+ Lilact
124
+ Copyright (C) 2024-2025 Arash Kazemi <contact.arash.kazemi@gmail.com>
125
+ All rights reserved.
126
+
127
+ BSD-2-Clause
128
+
129
+ Redistribution and use in source and binary forms, with or without
130
+ modification, are permitted provided that the following conditions are met:
131
+
132
+ * Redistributions of source code must retain the above copyright
133
+ notice, this list of conditions and the following disclaimer.
134
+ * Redistributions in binary form must reproduce the above copyright
135
+ notice, this list of conditions and the following disclaimer in the
136
+ documentation and/or other materials provided with the distribution.
137
+
138
+ --------------------------------------------------------------------------------
139
+
140
+ Lilact also includes the following libraries accessible as members of
141
+ the Lilact object:
142
+
143
+ @emotion/css:
144
+ Copyright (c) Emotion team and other contributors
145
+ MIT License
146
+
147
+ prop-types:
148
+ Copyright (c) 2013-present, Facebook, Inc.
149
+ MIT License
150
+
151
+ redux:
152
+ Copyright (c) 2015-present Dan Abramov
153
+ MIT License
154
+
155
+
156
+ * MIT License Notice:
157
+
158
+ Permission is hereby granted, free of charge, to any person obtaining a copy
159
+ of this software and associated documentation files (the "Software"), to deal
160
+ in the Software without restriction, including without limitation the rights
161
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
162
+ copies of the Software, and to permit persons to whom the Software is
163
+ furnished to do so, subject to the following conditions:
164
+
165
+ The above copyright notice and this permission notice shall be included in all
166
+ copies or substantial portions of the Software.
167
+
168
+ --------------------------------------------------------------------------------
169
+
170
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
171
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
172
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
173
+ ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
174
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
175
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
176
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
177
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
178
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
179
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
180
+
181
+ */
182
+ ${jssc}`;
183
+
184
+ fs.writeFile('./dist/' + filename, out, {}, function() {});
185
+ fs.writeFile('./root/' + filename, out, {}, function() {});
186
+ });
187
+
188
+ });
189
+ }
190
+ },
191
+ //new webpack.ProvidePlugin({
192
+ //Buffer: ['buffer', 'Buffer'],
193
+ // })
194
+ ]
195
+ }
196
+ };