@ktjs/shortcuts 0.6.6 → 0.7.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/dist/index.d.ts CHANGED
@@ -83,19 +83,11 @@ interface KTBaseAttribute {
83
83
  method?: 'POST' | 'GET' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS' | 'CONNECT' | 'TRACE' | otherstring;
84
84
  }
85
85
 
86
- type KTEventHandlersOrAttribute = {
87
- [EventName in keyof HTMLElementEventMap]?: ((ev: HTMLElementEventMap[EventName]) => void) | string;
88
- };
89
-
90
- /**
91
- * Event handlers with @ prefix (e.g., @click, @input)
92
- * When key starts with @, it's always registered as an event handler
93
- */
94
86
  type KTPrefixedEventHandlers = {
95
- [EventName in keyof HTMLElementEventMap as `@${EventName}`]?: (ev: HTMLElementEventMap[EventName]) => void;
87
+ [EventName in keyof HTMLElementEventMap as `on:${EventName}`]?: (ev: HTMLElementEventMap[EventName]) => void;
96
88
  };
97
89
 
98
- type KTAttribute = KTBaseAttribute & KTEventHandlersOrAttribute & KTPrefixedEventHandlers;
90
+ type KTAttribute = KTBaseAttribute & KTPrefixedEventHandlers;
99
91
 
100
92
  /**
101
93
  * Wrap `h`(or its shortcuts) with default attributes.
@@ -1 +1,113 @@
1
- var __ktjs_shortcuts__=function(t,o){"use strict";const n=t=>{const n=(n,e)=>o.h(t,n,e);return window.__ktjs__.mark(n,t),n},e=n("div"),s=n("span"),i=n("label"),r=n("p"),c=n("h1"),u=n("h2"),_=n("h3"),h=n("h4"),l=n("h5"),a=n("h6"),f=n("ul"),b=n("ol"),d=n("li"),p=n("button"),w=n("form"),y=n("input"),j=n("select"),g=n("option"),k=n("table"),m=n("thead"),v=n("tbody"),A=n("tr"),D=n("th"),q=n("td"),x=n("a"),z=n("img");return t.a=x,t.btn=p,t.div=e,t.form=w,t.h1=c,t.h2=u,t.h3=_,t.h4=h,t.h5=l,t.h6=a,t.img=z,t.input=y,t.label=i,t.li=d,t.ol=b,t.option=g,t.p=r,t.select=j,t.span=s,t.table=k,t.tbody=v,t.td=q,t.th=D,t.thead=m,t.tr=A,t.ul=f,t.withDefaults=(t,o)=>{"t"in t==!1&&window.__ktjs__.throws("withDefaults can only be used with h function or its alias"),null!==o&&"object"==typeof o||window.__ktjs__.throws("defaultAttr must be an object");const n="string"==typeof o.class?t=>{if("string"==typeof t){const n={...o};return n.class=t+" "+o.class,n}if(t&&"object"==typeof t){const n={...o,...t};return n.class=(t.class??"")+" "+o.class,n}}:t=>"string"==typeof t?{...o,class:t}:t&&"object"==typeof t?{...o,...t}:void 0;return"h"===t.t?(o,e,s)=>t(o,n(e),s):(o,e)=>t(n(o),e)},t}({},__ktjs_core__);
1
+ var __ktjs_shortcuts__ = (function (exports, core) {
2
+ 'use strict';
3
+
4
+ const aliasH = (tag) => {
5
+ const newFunc = (attr, content) => {
6
+ return core.h(tag, attr, content);
7
+ };
8
+ window.__ktjs__.mark(newFunc, tag);
9
+ return newFunc;
10
+ };
11
+
12
+ const div = aliasH('div');
13
+ const span = aliasH('span');
14
+ const label = aliasH('label');
15
+ const p = aliasH('p');
16
+ const h1 = aliasH('h1');
17
+ const h2 = aliasH('h2');
18
+ const h3 = aliasH('h3');
19
+ const h4 = aliasH('h4');
20
+ const h5 = aliasH('h5');
21
+ const h6 = aliasH('h6');
22
+ const ul = aliasH('ul');
23
+ const ol = aliasH('ol');
24
+ const li = aliasH('li');
25
+ const btn = aliasH('button');
26
+ const form = aliasH('form');
27
+ const input = aliasH('input');
28
+ const select = aliasH('select');
29
+ const option = aliasH('option');
30
+ const table = aliasH('table');
31
+ const thead = aliasH('thead');
32
+ const tbody = aliasH('tbody');
33
+ const tr = aliasH('tr');
34
+ const th = aliasH('th');
35
+ const td = aliasH('td');
36
+ const a = aliasH('a');
37
+ const img = aliasH('img');
38
+
39
+ /**
40
+ * Wrap `h`(or its shortcuts) with default attributes.
41
+ * - `defaultAttr.class` will be merged with the provided `class` attribute.
42
+ * @param func `h` or its shortcuts.
43
+ * @param defaultAttr default KTAttribute, must be an object.
44
+ * @returns new h function with default attributes.
45
+ */
46
+ const withDefaults = (func, defaultAttr) => {
47
+ if ('__ktjs_h__' in func === false) {
48
+ window.__ktjs__.throws('withDefaults can only be used with h function or its alias');
49
+ }
50
+ if (defaultAttr === null || typeof defaultAttr !== 'object') {
51
+ window.__ktjs__.throws('defaultAttr must be an object');
52
+ }
53
+ // create different merger for defaultAttr with class and not
54
+ const merge = typeof defaultAttr.class === 'string'
55
+ ? (attr) => {
56
+ if (typeof attr === 'string') {
57
+ const newAttr = { ...defaultAttr };
58
+ newAttr.class = attr + ' ' + defaultAttr.class;
59
+ return newAttr;
60
+ }
61
+ else if (attr && typeof attr === 'object') {
62
+ const newAttr = { ...defaultAttr, ...attr };
63
+ newAttr.class = (attr.class ?? '') + ' ' + defaultAttr.class;
64
+ return newAttr;
65
+ }
66
+ }
67
+ : (attr) => {
68
+ if (typeof attr === 'string') {
69
+ return { ...defaultAttr, class: attr };
70
+ }
71
+ else if (attr && typeof attr === 'object') {
72
+ return { ...defaultAttr, ...attr };
73
+ }
74
+ };
75
+ if (func.__ktjs_h__ === 'h') {
76
+ return ((tag, attr, content) => func(tag, merge(attr), content));
77
+ }
78
+ else {
79
+ return ((attr, content) => func(merge(attr), content));
80
+ }
81
+ };
82
+
83
+ exports.a = a;
84
+ exports.btn = btn;
85
+ exports.div = div;
86
+ exports.form = form;
87
+ exports.h1 = h1;
88
+ exports.h2 = h2;
89
+ exports.h3 = h3;
90
+ exports.h4 = h4;
91
+ exports.h5 = h5;
92
+ exports.h6 = h6;
93
+ exports.img = img;
94
+ exports.input = input;
95
+ exports.label = label;
96
+ exports.li = li;
97
+ exports.ol = ol;
98
+ exports.option = option;
99
+ exports.p = p;
100
+ exports.select = select;
101
+ exports.span = span;
102
+ exports.table = table;
103
+ exports.tbody = tbody;
104
+ exports.td = td;
105
+ exports.th = th;
106
+ exports.thead = thead;
107
+ exports.tr = tr;
108
+ exports.ul = ul;
109
+ exports.withDefaults = withDefaults;
110
+
111
+ return exports;
112
+
113
+ })({}, __ktjs_core__);
@@ -1 +1,147 @@
1
- var __ktjs_shortcuts__=function(t,n){"use strict";var r=function(t){var r=function(r,o){return n.h(t,r,o)};return window.__ktjs__.mark(r,t),r},o=r("div"),e=r("span"),u=r("label"),i=r("p"),c=r("h1"),f=r("h2"),s=r("h3"),a=r("h4"),l=r("h5"),h=r("h6"),p=r("ul"),_=r("ol"),d=r("li"),b=r("button"),v=r("form"),j=r("input"),y=r("select"),w=r("option"),g=r("table"),k=r("thead"),m=r("tbody"),E=r("tr"),O=r("th"),S=r("td"),A=r("a"),D=r("img"),q=function(){return q=Object.assign||function(t){for(var n,r=1,o=arguments.length;r<o;r++)for(var e in n=arguments[r])Object.prototype.hasOwnProperty.call(n,e)&&(t[e]=n[e]);return t},q.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;return t.a=A,t.btn=b,t.div=o,t.form=v,t.h1=c,t.h2=f,t.h3=s,t.h4=a,t.h5=l,t.h6=h,t.img=D,t.input=j,t.label=u,t.li=d,t.ol=_,t.option=w,t.p=i,t.select=y,t.span=e,t.table=g,t.tbody=m,t.td=S,t.th=O,t.thead=k,t.tr=E,t.ul=p,t.withDefaults=function(t,n){"t"in t==!1&&window.__ktjs__.throws("withDefaults can only be used with h function or its alias"),null!==n&&"object"==typeof n||window.__ktjs__.throws("defaultAttr must be an object");var r="string"==typeof n.class?function(t){var r,o;return"string"==typeof t?((o=q({},n)).class=t+" "+n.class,o):t&&"object"==typeof t?((o=q(q({},n),t)).class=(null!==(r=t.class)&&void 0!==r?r:"")+" "+n.class,o):void 0}:function(t){return"string"==typeof t?q(q({},n),{class:t}):t&&"object"==typeof t?q(q({},n),t):void 0};return"h"===t.t?function(n,o,e){return t(n,r(o),e)}:function(n,o){return t(r(n),o)}},t}({},__ktjs_core__);
1
+ var __ktjs_shortcuts__ = (function (exports, core) {
2
+ 'use strict';
3
+
4
+ var aliasH = function (tag) {
5
+ var newFunc = function (attr, content) {
6
+ return core.h(tag, attr, content);
7
+ };
8
+ window.__ktjs__.mark(newFunc, tag);
9
+ return newFunc;
10
+ };
11
+
12
+ var div = aliasH('div');
13
+ var span = aliasH('span');
14
+ var label = aliasH('label');
15
+ var p = aliasH('p');
16
+ var h1 = aliasH('h1');
17
+ var h2 = aliasH('h2');
18
+ var h3 = aliasH('h3');
19
+ var h4 = aliasH('h4');
20
+ var h5 = aliasH('h5');
21
+ var h6 = aliasH('h6');
22
+ var ul = aliasH('ul');
23
+ var ol = aliasH('ol');
24
+ var li = aliasH('li');
25
+ var btn = aliasH('button');
26
+ var form = aliasH('form');
27
+ var input = aliasH('input');
28
+ var select = aliasH('select');
29
+ var option = aliasH('option');
30
+ var table = aliasH('table');
31
+ var thead = aliasH('thead');
32
+ var tbody = aliasH('tbody');
33
+ var tr = aliasH('tr');
34
+ var th = aliasH('th');
35
+ var td = aliasH('td');
36
+ var a = aliasH('a');
37
+ var img = aliasH('img');
38
+
39
+ /******************************************************************************
40
+ Copyright (c) Microsoft Corporation.
41
+
42
+ Permission to use, copy, modify, and/or distribute this software for any
43
+ purpose with or without fee is hereby granted.
44
+
45
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
46
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
47
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
48
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
49
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
50
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
51
+ PERFORMANCE OF THIS SOFTWARE.
52
+ ***************************************************************************** */
53
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
54
+
55
+
56
+ var __assign = function() {
57
+ __assign = Object.assign || function __assign(t) {
58
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
59
+ s = arguments[i];
60
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
61
+ }
62
+ return t;
63
+ };
64
+ return __assign.apply(this, arguments);
65
+ };
66
+
67
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
68
+ var e = new Error(message);
69
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
70
+ };
71
+
72
+ /**
73
+ * Wrap `h`(or its shortcuts) with default attributes.
74
+ * - `defaultAttr.class` will be merged with the provided `class` attribute.
75
+ * @param func `h` or its shortcuts.
76
+ * @param defaultAttr default KTAttribute, must be an object.
77
+ * @returns new h function with default attributes.
78
+ */
79
+ var withDefaults = function (func, defaultAttr) {
80
+ if ('__ktjs_h__' in func === false) {
81
+ window.__ktjs__.throws('withDefaults can only be used with h function or its alias');
82
+ }
83
+ if (defaultAttr === null || typeof defaultAttr !== 'object') {
84
+ window.__ktjs__.throws('defaultAttr must be an object');
85
+ }
86
+ // create different merger for defaultAttr with class and not
87
+ var merge = typeof defaultAttr.class === 'string'
88
+ ? function (attr) {
89
+ var _a;
90
+ if (typeof attr === 'string') {
91
+ var newAttr = __assign({}, defaultAttr);
92
+ newAttr.class = attr + ' ' + defaultAttr.class;
93
+ return newAttr;
94
+ }
95
+ else if (attr && typeof attr === 'object') {
96
+ var newAttr = __assign(__assign({}, defaultAttr), attr);
97
+ newAttr.class = ((_a = attr.class) !== null && _a !== void 0 ? _a : '') + ' ' + defaultAttr.class;
98
+ return newAttr;
99
+ }
100
+ }
101
+ : function (attr) {
102
+ if (typeof attr === 'string') {
103
+ return __assign(__assign({}, defaultAttr), { class: attr });
104
+ }
105
+ else if (attr && typeof attr === 'object') {
106
+ return __assign(__assign({}, defaultAttr), attr);
107
+ }
108
+ };
109
+ if (func.__ktjs_h__ === 'h') {
110
+ return (function (tag, attr, content) { return func(tag, merge(attr), content); });
111
+ }
112
+ else {
113
+ return (function (attr, content) { return func(merge(attr), content); });
114
+ }
115
+ };
116
+
117
+ exports.a = a;
118
+ exports.btn = btn;
119
+ exports.div = div;
120
+ exports.form = form;
121
+ exports.h1 = h1;
122
+ exports.h2 = h2;
123
+ exports.h3 = h3;
124
+ exports.h4 = h4;
125
+ exports.h5 = h5;
126
+ exports.h6 = h6;
127
+ exports.img = img;
128
+ exports.input = input;
129
+ exports.label = label;
130
+ exports.li = li;
131
+ exports.ol = ol;
132
+ exports.option = option;
133
+ exports.p = p;
134
+ exports.select = select;
135
+ exports.span = span;
136
+ exports.table = table;
137
+ exports.tbody = tbody;
138
+ exports.td = td;
139
+ exports.th = th;
140
+ exports.thead = thead;
141
+ exports.tr = tr;
142
+ exports.ul = ul;
143
+ exports.withDefaults = withDefaults;
144
+
145
+ return exports;
146
+
147
+ })({}, __ktjs_core__);
package/dist/index.mjs CHANGED
@@ -1 +1,82 @@
1
- import{h as t}from"@ktjs/core";const o=o=>{const e=(e,n)=>t(o,e,n);return window.__ktjs__.mark(e,o),e},e=o("div"),n=o("span"),i=o("label"),r=o("p"),s=o("h1"),c=o("h2"),l=o("h3"),f=o("h4"),h=o("h5"),u=o("h6"),a=o("ul"),p=o("ol"),b=o("li"),d=o("button"),w=o("form"),y=o("input"),j=o("select"),m=o("option"),_=o("table"),g=o("thead"),k=o("tbody"),v=o("tr"),x=o("th"),A=o("td"),D=o("a"),q=o("img"),z=(t,o)=>{"t"in t==!1&&window.__ktjs__.throws("withDefaults can only be used with h function or its alias"),null!==o&&"object"==typeof o||window.__ktjs__.throws("defaultAttr must be an object");const e="string"==typeof o.class?t=>{if("string"==typeof t){const e={...o};return e.class=t+" "+o.class,e}if(t&&"object"==typeof t){const e={...o,...t};return e.class=(t.class??"")+" "+o.class,e}}:t=>"string"==typeof t?{...o,class:t}:t&&"object"==typeof t?{...o,...t}:void 0;return"h"===t.t?(o,n,i)=>t(o,e(n),i):(o,n)=>t(e(o),n)};export{D as a,d as btn,e as div,w as form,s as h1,c as h2,l as h3,f as h4,h as h5,u as h6,q as img,y as input,i as label,b as li,p as ol,m as option,r as p,j as select,n as span,_ as table,k as tbody,A as td,x as th,g as thead,v as tr,a as ul,z as withDefaults};
1
+ import { h } from '@ktjs/core';
2
+
3
+ const aliasH = (tag) => {
4
+ const newFunc = (attr, content) => {
5
+ return h(tag, attr, content);
6
+ };
7
+ window.__ktjs__.mark(newFunc, tag);
8
+ return newFunc;
9
+ };
10
+
11
+ const div = aliasH('div');
12
+ const span = aliasH('span');
13
+ const label = aliasH('label');
14
+ const p = aliasH('p');
15
+ const h1 = aliasH('h1');
16
+ const h2 = aliasH('h2');
17
+ const h3 = aliasH('h3');
18
+ const h4 = aliasH('h4');
19
+ const h5 = aliasH('h5');
20
+ const h6 = aliasH('h6');
21
+ const ul = aliasH('ul');
22
+ const ol = aliasH('ol');
23
+ const li = aliasH('li');
24
+ const btn = aliasH('button');
25
+ const form = aliasH('form');
26
+ const input = aliasH('input');
27
+ const select = aliasH('select');
28
+ const option = aliasH('option');
29
+ const table = aliasH('table');
30
+ const thead = aliasH('thead');
31
+ const tbody = aliasH('tbody');
32
+ const tr = aliasH('tr');
33
+ const th = aliasH('th');
34
+ const td = aliasH('td');
35
+ const a = aliasH('a');
36
+ const img = aliasH('img');
37
+
38
+ /**
39
+ * Wrap `h`(or its shortcuts) with default attributes.
40
+ * - `defaultAttr.class` will be merged with the provided `class` attribute.
41
+ * @param func `h` or its shortcuts.
42
+ * @param defaultAttr default KTAttribute, must be an object.
43
+ * @returns new h function with default attributes.
44
+ */
45
+ const withDefaults = (func, defaultAttr) => {
46
+ if ('__ktjs_h__' in func === false) {
47
+ window.__ktjs__.throws('withDefaults can only be used with h function or its alias');
48
+ }
49
+ if (defaultAttr === null || typeof defaultAttr !== 'object') {
50
+ window.__ktjs__.throws('defaultAttr must be an object');
51
+ }
52
+ // create different merger for defaultAttr with class and not
53
+ const merge = typeof defaultAttr.class === 'string'
54
+ ? (attr) => {
55
+ if (typeof attr === 'string') {
56
+ const newAttr = { ...defaultAttr };
57
+ newAttr.class = attr + ' ' + defaultAttr.class;
58
+ return newAttr;
59
+ }
60
+ else if (attr && typeof attr === 'object') {
61
+ const newAttr = { ...defaultAttr, ...attr };
62
+ newAttr.class = (attr.class ?? '') + ' ' + defaultAttr.class;
63
+ return newAttr;
64
+ }
65
+ }
66
+ : (attr) => {
67
+ if (typeof attr === 'string') {
68
+ return { ...defaultAttr, class: attr };
69
+ }
70
+ else if (attr && typeof attr === 'object') {
71
+ return { ...defaultAttr, ...attr };
72
+ }
73
+ };
74
+ if (func.__ktjs_h__ === 'h') {
75
+ return ((tag, attr, content) => func(tag, merge(attr), content));
76
+ }
77
+ else {
78
+ return ((attr, content) => func(merge(attr), content));
79
+ }
80
+ };
81
+
82
+ export { a, btn, div, form, h1, h2, h3, h4, h5, h6, img, input, label, li, ol, option, p, select, span, table, tbody, td, th, thead, tr, ul, withDefaults };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ktjs/shortcuts",
3
- "version": "0.6.6",
3
+ "version": "0.7.3",
4
4
  "description": "Shortcut functions for kt.js - common DOM operations",
5
5
  "type": "module",
6
6
  "module": "./dist/index.mjs",
@@ -30,7 +30,7 @@
30
30
  "directory": "packages/shortcuts"
31
31
  },
32
32
  "dependencies": {
33
- "@ktjs/core": "0.6.6"
33
+ "@ktjs/core": "0.7.3"
34
34
  },
35
35
  "scripts": {
36
36
  "build": "rollup -c rollup.config.mjs",