@mathiscode/pucc 1.0.0 → 1.0.3

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ # MIT License
2
+
3
+ Copyright (c) 2026 Jay Mathis
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,6 +1,16 @@
1
1
  # Pucc
2
2
 
3
- Power User Console Component - A browser library that provides a console command system.
3
+ [![Live Demo](https://img.shields.io/badge/Live%20Demo-rebeccapurple)](https://mathiscode.github.io/pucc/)
4
+
5
+ [![npm](https://img.shields.io/npm/v/@mathiscode/pucc)](https://www.npmjs.com/package/@mathiscode/pucc)
6
+ [![Created](https://img.shields.io/github/created-at/mathiscode/pucc?style=flat&label=created&color=success)](https://github.com/mathiscode/pucc/pulse)
7
+ [![Star on GitHub](https://img.shields.io/github/stars/mathiscode/pucc?style=flat&logo=github&label=⭐️%20stars)](https://github.com/mathiscode/pucc/stargazers)
8
+ [![GitHub forks](https://img.shields.io/github/forks/mathiscode/pucc?style=flat&logo=github&label=🔀%20forks)](https://github.com/mathiscode/pucc/forks)
9
+ [![GitHub watchers](https://img.shields.io/github/watchers/mathiscode/pucc?style=flat&logo=github&label=👀%20watchers)](https://github.com/mathiscode/pucc/watchers)
10
+ [![Sponsors](https://img.shields.io/github/sponsors/mathiscode?color=red&logo=github&label=💖%20sponsors)](https://github.com/sponsors/mathiscode)
11
+ [![Contributors](https://img.shields.io/github/contributors/mathiscode/pucc?color=yellow&logo=github&label=👥%20contributors)](https://github.com/mathiscode/pucc/graphs/contributors)
12
+
13
+ Power User Console Component - A browser library that provides a console command system.
4
14
 
5
15
  Register custom commands and execute them via the browser console with a `$` prefix or via the dropdown or embedded terminal Custom Element.
6
16
 
@@ -92,40 +102,49 @@ $new customer name="John Smith" balance=5400
92
102
 
93
103
  ### Module Import (ESM)
94
104
 
105
+ When using ESM, no global instance is created automatically. You have full control over how Pucc instances are created and used:
106
+
95
107
  ```javascript
96
108
  import { Pucc } from 'pucc';
97
109
 
98
- // When using ESM, no global instance is created automatically
99
- // You have full control over whether to create a global instance
100
- // or use terminal-only commands
101
-
102
- // Option 1: Create a global instance (like IIFE build)
110
+ // Create a Pucc instance
111
+ // Commands are automatically registered on window (for console access)
103
112
  const shell = new Pucc();
104
- shell.initialize();
105
- // Now commands are available: $help(), $about()
106
113
 
107
- // Option 2: Create a terminal-only instance
108
- const shell = new Pucc({ enableGlobalRegistrations: false });
109
- // Commands only available in terminal elements, not globally
114
+ // Add commands - they're immediately available in console AND terminals
115
+ shell.addCommand('greet', (args) => {
116
+ console.log(`Hello, ${args._[0] || 'World'}!`);
117
+ }, 'Greet someone');
118
+
119
+ // Commands are now available:
120
+ // - In browser console: $greet('Alice') or greet('Alice')
121
+ // - In terminal elements: greet Alice
110
122
  ```
111
123
 
112
- ### Disabling Global Command Registrations
124
+ ### Understanding Global Registrations
113
125
 
114
- By default, commands are registered globally on the `window` object, making them accessible from the browser console. If you want to limit command execution to only the terminal element (avoiding global namespace pollution), you can disable global registrations:
126
+ By default, `enableGlobalRegistrations: true` registers commands on the `window` object, making them accessible from the browser console. This does NOT affect terminal access - terminals can use any Pucc instance regardless of this setting.
115
127
 
116
128
  ```javascript
117
129
  import { Pucc } from 'pucc';
118
130
 
119
- // Create a Pucc instance with global registrations disabled
120
- const shell = new Pucc({ enableGlobalRegistrations: false });
131
+ // Option 1: Commands available in console AND terminals (default)
132
+ const shell = new Pucc();
133
+ shell.addCommand('test', () => console.log('test'), 'Test command');
134
+ // Available as: $test() in console, or "test" in terminals
121
135
 
122
- // Commands will only be available through the terminal
123
- // They will NOT be accessible via window.$commandName
124
- shell.addCommand('mycommand', (args) => {
125
- console.log('This command is only available in the terminal');
126
- }, 'A terminal-only command');
136
+ // Option 2: Commands available ONLY in terminals (not in console)
137
+ const shell = new Pucc({ enableGlobalRegistrations: false });
138
+ shell.addCommand('test', () => console.log('test'), 'Test command');
139
+ // Available as: "test" in terminals only (not on window)
127
140
  ```
128
141
 
142
+ **Key Points:**
143
+
144
+ - `enableGlobalRegistrations` only controls whether commands appear on `window` (for console access)
145
+ - Terminals can use ANY Pucc instance, regardless of this setting
146
+ - Set to `false` if you want to avoid polluting the global namespace
147
+
129
148
  ### Custom Command Prefix
130
149
 
131
150
  By default, commands use the `$` prefix (e.g., `$help`, `$about`). You can customize this prefix when creating a Pucc instance:
@@ -166,19 +185,39 @@ shell.addCommand('greet', (args) => {
166
185
 
167
186
  **Note:** The prefix must be a valid JavaScript identifier (starts with a letter, underscore, or dollar sign; can only contain letters, digits, underscores, and dollar signs). The prefix is used for console commands and is automatically stripped when parsing command input. Commands can always be called with or without the prefix in the terminal.
168
187
 
169
- ### Passing Pucc Options to Terminal Element
188
+ ### Using Terminal Elements
189
+
190
+ The `<pucc-terminal>` custom element can use either:
170
191
 
171
- When using the `pucc-terminal` custom element, you can pass Pucc constructor options in two ways:
192
+ 1. A shared global instance (`window.Pucc`) - created automatically in IIFE builds
193
+ 2. Its own isolated instance - configured via `puccOptions`
194
+
195
+ **Configuring a Terminal with Its Own Instance:**
172
196
 
173
197
  **Via attribute (for simple options):**
174
198
 
175
199
  ```html
176
200
  <pucc-terminal
177
201
  embedded="true"
202
+ height="300px"
203
+ theme="dark"
204
+ prompt="# "
205
+ hotkey="alt+s"
206
+ initial-content="Welcome to my terminal!"
178
207
  pucc-options='{"enableGlobalRegistrations": false, "commandPrefix": "_"}'>
179
208
  </pucc-terminal>
180
209
  ```
181
210
 
211
+ **Terminal Attributes:**
212
+
213
+ - `embedded` - Set to `"true"` for embedded mode (always visible)
214
+ - `height` - Terminal height (e.g., `"300px"`, `"50vh"`)
215
+ - `theme` - Color theme (`"dark"` or `"light"`)
216
+ - `prompt` - Custom prompt text (default: `"$ "`)
217
+ - `hotkey` - Keyboard shortcut for dropdown terminals (e.g., `"alt+s"`, `"ctrl+shift+t"`)
218
+ - `initial-content` - Custom initial content to display instead of the default welcome message (supports newlines with `\n`)
219
+ - `pucc-options` - JSON string with Pucc constructor options (see below)
220
+
182
221
  **Via property (for full functionality, including functions):**
183
222
 
184
223
  ```javascript
@@ -204,8 +243,73 @@ terminal.puccOptions = {
204
243
  };
205
244
  ```
206
245
 
246
+ **Adding Commands to a Terminal Element:**
247
+
248
+ If a terminal uses its own instance (via `puccOptions`), you can add commands to it:
249
+
250
+ ```javascript
251
+ const terminal = document.querySelector('pucc-terminal');
252
+
253
+ // Get the terminal's Pucc instance
254
+ const shell = terminal.shellInstance;
255
+
256
+ if (shell) {
257
+ // Add commands directly to the terminal's instance
258
+ shell.addCommand('mycommand', (args) => {
259
+ console.log('Command executed in terminal');
260
+ }, 'My custom command');
261
+ }
262
+ ```
263
+
264
+ **Using the Global Instance:**
265
+
266
+ If a terminal doesn't have `puccOptions` set, it automatically uses `window.Pucc` (if available). In this case, commands added to the global instance are available in all terminals:
267
+
268
+ ```javascript
269
+ // In IIFE builds, window.Pucc is created automatically
270
+ // In ESM builds, create it yourself:
271
+ window.Pucc = new Pucc();
272
+
273
+ // Add commands - they're available in all terminals using the global instance
274
+ shell.addCommand('shared', () => console.log('Shared command'), 'Shared command');
275
+ ```
276
+
207
277
  **Note:** The `pucc-options` attribute only supports JSON-serializable options (`enableGlobalRegistrations`, `commandPrefix`). For options that include functions (`customHelpHandler`, `initialCommands`), use the `puccOptions` property instead.
208
278
 
279
+ ### Customizing Terminal Appearance with CSS
280
+
281
+ The terminal component supports CSS custom properties for advanced styling:
282
+
283
+ ```css
284
+ pucc-terminal {
285
+ --shell-bg: #1a1a1a;
286
+ --shell-fg: #e0e0e0;
287
+ --shell-accent: #00aaff;
288
+ --shell-border: rgba(255, 255, 255, 0.1);
289
+ --shell-font-family: 'Courier New', monospace;
290
+ --shell-font-size: 16px;
291
+ --shell-padding: 20px;
292
+ --shell-animation-duration: 0.3s;
293
+ --shell-border-radius: 12px;
294
+ --shell-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
295
+ --shell-backdrop-blur: 15px;
296
+ }
297
+ ```
298
+
299
+ **Available CSS Variables:**
300
+
301
+ - `--shell-bg` - Background color
302
+ - `--shell-fg` - Foreground/text color
303
+ - `--shell-accent` - Accent color (cursor, selection)
304
+ - `--shell-border` - Border color
305
+ - `--shell-font-family` - Font family
306
+ - `--shell-font-size` - Font size
307
+ - `--shell-padding` - Padding
308
+ - `--shell-animation-duration` - Animation duration
309
+ - `--shell-border-radius` - Border radius
310
+ - `--shell-shadow` - Box shadow
311
+ - `--shell-backdrop-blur` - Backdrop blur amount (dropdown terminals only)
312
+
209
313
  ## API Reference
210
314
 
211
315
  ### `new Pucc(options?)`
@@ -217,42 +321,52 @@ Create a new Pucc instance.
217
321
  - `options` (object, optional): Configuration options
218
322
  - `customHelpHandler` (function, optional): Custom handler for the `help` command
219
323
  - `initialCommands` (Command[], optional): Array of commands to register on initialization
220
- - `enableGlobalRegistrations` (boolean, optional): Whether to register commands globally on `window`. Defaults to `true`. Set to `false` to limit commands to the dropdown/embedded terminal only.
221
- - `commandPrefix` (string, optional): Custom prefix for console commands. Defaults to `$`. Must be a valid JavaScript identifier (starts with letter, underscore, or dollar sign; can contain letters, digits, underscores, and dollar signs). Commands can be called with or without the prefix.
324
+ - `enableGlobalRegistrations` (boolean, optional): Whether to register commands globally on `window` for console access. Defaults to `true`. Set to `false` to avoid polluting the global namespace. **Note:** This only affects console access, not terminal access - terminals can use any instance regardless of this setting.
325
+ - `commandPrefix` (string, optional): Custom prefix for console commands. Defaults to `$`. Must be a valid JavaScript identifier (starts with letter, underscore, or dollar sign; can contain letters, digits, underscores, and dollar signs). Commands can be called with or without the prefix in terminals.
222
326
 
223
327
  **Example:**
224
328
 
225
329
  ```javascript
226
330
  // Default behavior (global registrations enabled, $ prefix)
227
331
  const shell = new Pucc();
332
+ // Commands immediately available in console and terminals
228
333
 
229
- // Disable global registrations
334
+ // Disable global registrations (console access only, terminals still work)
230
335
  const shell = new Pucc({ enableGlobalRegistrations: false });
336
+ // Commands available in terminals, NOT in console
231
337
 
232
- // Use custom command prefix (must be a valid JavaScript identifier)
338
+ // Use custom command prefix
233
339
  const shell = new Pucc({ commandPrefix: 'cmd_' });
234
- // Now commands can be called as cmd_help, cmd_about, etc.
340
+ // Console: cmd_help(), Terminal: help or cmd_help
235
341
  ```
236
342
 
237
- ### `Pucc.addCommand(name, handler, description)`
343
+ ### `shell.addCommand(name, handler, description)`
238
344
 
239
- Register a new command.
345
+ Register a new command on a Pucc instance. The command is immediately available in terminals and (if `enableGlobalRegistrations` is true) in the console.
240
346
 
241
347
  **Parameters:**
242
348
 
243
349
  - `name` (string): Command name (without prefix)
244
- - `handler` (function): Command handler function `(args: ParsedArgs) => void | Promise<void>`
245
- - `description` (string): Command description (shown in `$help`)
350
+ - `handler` (function): Command handler function `(args: ParsedArgs, shell?: Pucc) => void | Promise<void>`
351
+ - `description` (string): Command description (shown in `help`)
246
352
 
247
353
  **Example:**
248
354
 
249
355
  ```javascript
250
- Pucc.addCommand('greet', (args) => {
356
+ const shell = new Pucc();
357
+
358
+ // Add a command - immediately available
359
+ shell.addCommand('greet', (args) => {
251
360
  const name = args.name || args._[0] || 'World';
252
361
  console.log(`Hello, ${name}!`);
253
362
  }, 'Greet someone by name');
363
+
364
+ // In console: $greet('Alice') or greet('Alice')
365
+ // In terminal: greet Alice or greet name=Alice
254
366
  ```
255
367
 
368
+ **Note:** In IIFE builds, you can also use `Pucc.addCommand()` which adds to the global instance automatically created.
369
+
256
370
  ### `ParsedArgs`
257
371
 
258
372
  The argument object passed to command handlers:
@@ -293,7 +407,7 @@ pnpm type-check
293
407
 
294
408
  ### Project Structure
295
409
 
296
- ```
410
+ ```text
297
411
  pucc/
298
412
  ├── src/
299
413
  │ ├── index.ts # Main entry point
@@ -302,13 +416,31 @@ pucc/
302
416
  │ │ └── CommandParser.ts # Command parser
303
417
  │ ├── commands/
304
418
  │ │ ├── help.ts # $help command
305
- │ │ └── about.ts # $about command
306
- │ └── types.ts # Type definitions
419
+ │ │ ├── about.ts # $about command
420
+ └── echo.ts # $echo command
421
+ │ ├── components/
422
+ │ │ ├── ShellTerminal.ts # Terminal custom element
423
+ │ │ └── TerminalLogger.ts # Terminal logger component
424
+ │ ├── types.ts # Type definitions
425
+ │ └── demo.css # Demo styles
307
426
  ├── config/
308
427
  │ └── build.js # Build configuration
309
- └── dist/ # Build output
428
+ ├── public/ # Demo and development files
429
+ ├── dist/ # Build output
430
+ ├── eslint.config.mts # ESLint configuration
431
+ ├── tsconfig.json # TypeScript configuration
432
+ └── server.js # Development server
310
433
  ```
311
434
 
312
435
  ## License
313
436
 
314
- MIT
437
+ [MIT](LICENSE)
438
+
439
+ ## About the Author
440
+
441
+ Pucc is created and maintained by [Jay Mathis](https://github.com/mathiscode), a developer passionate about building useful tools for the web.
442
+
443
+ Connect and explore:
444
+
445
+ - [GitHub Profile](https://github.com/mathiscode) - Check out my other projects and contributions
446
+ - [Website](https://jaymath.is) - Learn more about me and my work
package/dist/index.html CHANGED
@@ -20,7 +20,7 @@
20
20
  <span>View on GitHub</span>
21
21
  </a>
22
22
  </div>
23
- <p>A browser library that provides a console command system. Register custom commands and execute them via the browser console with a <code>$</code> (configurable) prefix or via the dropdown or embedded terminal Custom Element.</p>
23
+ <p>A browser library that provides a console command system. Register custom commands and execute them via the browser console with a <code>$</code> (configurable) prefix or via the dropdown or embedded terminal Custom Element (<code>pucc-terminal</code>).</p>
24
24
  <br />
25
25
  <p>This can be very useful for web apps that need to provide a console for users to interact with the app, bypassing the UI for power users.</p>
26
26
  </div>
@@ -139,7 +139,7 @@ about</code></pre>
139
139
  <div class="card">
140
140
  <h2>Module Import (ESM)</h2>
141
141
  <p>When using ESM, no global instance is created automatically. You have full control:</p>
142
- <pre><code>import { Pucc } from 'pucc';
142
+ <pre><code>import { Pucc } from '@mathiscode/pucc';
143
143
 
144
144
  // Option 1: Create a global instance (like IIFE build)
145
145
  const shell = new Pucc();
@@ -154,7 +154,7 @@ const shell = new Pucc({ enableGlobalRegistrations: false });
154
154
  <div class="card">
155
155
  <h2>Disabling Global Registrations</h2>
156
156
  <p>Limit commands to the terminal only (avoiding global namespace pollution):</p>
157
- <pre><code>import { Pucc } from 'pucc';
157
+ <pre><code>import { Pucc } from '@mathiscode/pucc';
158
158
 
159
159
  const shell = new Pucc({ enableGlobalRegistrations: false });
160
160
 
@@ -168,7 +168,7 @@ shell.addCommand('mycommand', (args) => {
168
168
  <div class="card">
169
169
  <h2>Custom Command Prefix</h2>
170
170
  <p>Customize the command prefix (must be a valid JavaScript identifier):</p>
171
- <pre><code>import { Pucc } from 'pucc';
171
+ <pre><code>import { Pucc } from '@mathiscode/pucc';
172
172
 
173
173
  const shell = new Pucc({ commandPrefix: 'cmd' });
174
174
 
package/dist/pucc.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @mathiscode/pucc v1.0.0 */
1
+ /*! @mathiscode/pucc v1.0.1 */
2
2
 
3
3
  // src/core/CommandParser.ts
4
4
  var CommandParser = class {
package/dist/pucc.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @mathiscode/pucc v1.0.0 */
1
+ /*! @mathiscode/pucc v1.0.1 */
2
2
  "use strict";
3
3
  (() => {
4
4
  // src/core/CommandParser.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mathiscode/pucc",
3
- "version": "1.0.0",
3
+ "version": "1.0.3",
4
4
  "license": "MIT",
5
5
  "description": "Power User Console Component - A browser console command system library",
6
6
  "author": {