create-basicjs 0.1.3 → 0.1.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-basicjs",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Create a project with basic.js and the JS-Component Kit, ready to build with AI tools.",
5
5
  "bin": {
6
6
  "create-basicjs": "bin/create-basicjs.js"
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
@@ -10,7 +10,9 @@ UI COMPONENT TEMPLATE
10
10
  - The menu opens when the mouse is over it. On a touch device there is no hover, so it opens with a tap:
11
11
  the first tap opens the menu (it does not select an item, because the texts are not visible when it is closed),
12
12
  the second tap selects the item and closes the menu. A tap outside the menu also closes it.
13
- -- openOnClick: "auto" (touch device: tap, mouse: hover), 1: always tap, 0: always hover.
13
+ -- openOnClick: "auto" (touch device: tap, mouse: hover), 1: always tap, 0: always hover, "direct": a tap selects at
14
+ once and the menu stays closed (2026-11-02, for a short menu with clear icons).
15
+ -- itemHeight: the height of a button item. A page fitted with page.fit() is zoomed: for a finger give Ex: 44 / page.zoom.
14
16
  -- leftMenu.setOpenOnClick(1) changes it later.
15
17
 
16
18
  Started Date: December 2024
@@ -26,6 +28,7 @@ Webpage: https://bug7a.github.io/js-components/
26
28
  const LeftMenuDefaults = {
27
29
  key: "0",
28
30
  expandedWidth: 250, // Expanded width on hover
31
+ itemHeight: 40, // The height of a button item
29
32
  topBarHeight: 40, // Height of top bar to account for
30
33
  backgroundColor: "#141414", // Menu background color
31
34
  hoverColor: "rgba(255, 255, 255, 0.05)", // Hover color for buttons
@@ -82,7 +85,7 @@ const LeftMenu = function(params = {}) {
82
85
 
83
86
  const buttonBox = startBox({
84
87
  width: "100%",
85
- height: 40,
88
+ height: box.itemHeight,
86
89
  color: "transparent",
87
90
  clickable: 1,
88
91
  position: "relative",
@@ -129,7 +132,7 @@ const LeftMenu = function(params = {}) {
129
132
  if (event) event.stopPropagation();
130
133
 
131
134
  // WHY: Touch device, closed menu: only the icons are visible. The first tap opens the menu, it does not select.
132
- if (useTapMode && !isExpanded) {
135
+ if (useTapMode && !isExpanded && box.openOnClick !== "direct") {
133
136
  expandMenu();
134
137
  return;
135
138
  }
@@ -278,6 +281,8 @@ const LeftMenu = function(params = {}) {
278
281
  box.openOnClick = openOnClick;
279
282
  if (openOnClick === "auto") {
280
283
  useTapMode = isTouchDevice();
284
+ } else if (openOnClick === "direct") {
285
+ useTapMode = 1;
281
286
  } else {
282
287
  useTapMode = basic.isOn(openOnClick) ? 1 : 0;
283
288
  }
@@ -465,7 +470,7 @@ const LeftMenu = function(params = {}) {
465
470
 
466
471
  // Tap on the menu (also on an empty place of it): open it. (Touch device)
467
472
  box.on("click", function() {
468
- if (useTapMode && !isExpanded) expandMenu();
473
+ if (useTapMode && !isExpanded && box.openOnClick !== "direct") expandMenu();
469
474
  });
470
475
 
471
476
  // WHY: Capture, so it also works when the tap is stopped by another object. (Ex: a page that closes its own menu)
@@ -1,2 +1,2 @@
1
1
  /* Bismillah */
2
- "use strict";const LeftMenuDefaults={key:"0",expandedWidth:250,topBarHeight:40,backgroundColor:"#141414",hoverColor:"rgba(255, 255, 255, 0.05)",selectedColor:"#583432",titleColor:"#8E342F",textColor:"rgba(255, 255, 255, 0.6)",selectedTextColor:"rgba(255, 255, 255, 0.95)",invertIconColor:1,openOnClick:"auto",items:[],onItemClick:function(t){},onMenuToggle:function(t){}},LeftMenu=function(t={}){mergeIntoIfMissing(t,LeftMenuDefaults);let o=startObject(t),e=0,n=null,r=0;const a=[],i=[];o.publicVar=1,o.state="collapsed";const c=function(t,e){if("normal"===e)return t.css.background="transparent",t.icon.opacity=.6,void(t.textLabel.textColor=o.textColor);const n="selected"===e?o.selectedColor:o.hoverColor;t.css.background=`linear-gradient(to right, ${n} 0%, rgba(0,0,0,0) 100%)`,t.icon.opacity=1,t.textLabel.textColor=o.selectedTextColor},l=function(t){const a=startBox({width:"100%",height:40,color:"transparent",clickable:1,position:"relative"});return a.setMotion("background-color 0.2s"),a.cursor="pointer",a.data=t,HGroup({align:"left center",gap:20,padding:[8,0]}),a.icon=Icon({width:24,height:24,color:"transparent",opacity:.6}),a.icon.load(t.icon),1==o.invertIconColor&&(that.css.filter="invert(100%)"),a.textLabel=Label({text:t.text,textColor:o.textColor,fontSize:18,color:"transparent"}),endGroup(),endBox(),a.on("click",function(a,i){i&&i.stopPropagation(),!r||e?(n!=t.key&&(t.dontSelect||s(t.key),o.onItemClick(t)),r&&p()):u()}),a.on("mouseover",function(){r||n!=t.key&&c(a,"hover")}),a.on("mouseout",function(){r||n!=t.key&&c(a,"normal")}),a},d=function(t){const e=startBox({width:"100%",height:29,color:"transparent",clickable:1,position:"relative"});e.data=t,Box(0,0,100,1,{color:o.titleColor}),that.top=14,that.opacity=.5,AutoLayout({align:"left center",padding:[40,0]});return Label({text:t.text,textColor:o.titleColor,fontSize:12,color:o.backgroundColor,padding:[12,0]}).css={fontWeight:"bold",textTransform:"uppercase"},endAutoLayout(),endBox(),e};o.clearSelection=function(){if(n){const t=i.find(t=>t.data.key===n);t&&"button"===t.data.type&&(c(t,"normal"),t.cursor="pointer"),n=null}};const s=function(t){o.clearSelection();const e=i.find(o=>o.data.key===t);e&&"button"===e.data.type&&(c(e,"selected"),e.cursor="default",n=t)},u=function(){e||(e=1,o.state="expanded",o.width=o.expandedWidth,o.onMenuToggle(1))},p=function(){e&&(e=0,o.state="collapsed",o.width=40,o.onMenuToggle(0))};o.setOpenOnClick=function(t){return o.openOnClick=t,r="auto"===t?window.matchMedia&&window.matchMedia("(hover: none)").matches||window.matchMedia&&window.matchMedia("(pointer: coarse)").matches?1:basic.isMobile():basic.isOn(t)?1:0,r||p(),r},o.isTapMode=function(){return r};const h=o.remove;o.superRemove=h,o.remove=function(){o&&(page.remove_onResize(f),h.call(o),o=null)},o.addItemToTop=function(t){a.push(t);const e="button"===t.type?l(t):d(t);return i.push(e),o.topBox.add(e),e},o.addItemToBottom=function(t){a.push(t);const e="button"===t.type?l(t):d(t);return i.push(e),o.bottomBox.add(e),e},o.removeItem=function(t){t===n&&o.clearSelection();const e=a.findIndex(o=>o.key===t);if(-1!==e){i[e].remove(),a.splice(e,1),i.splice(e,1)}},o.getSelectedItem=function(){return a.find(t=>t.key===n)},o.setSelectedItem=function(t){s(t)},o.expand=function(){u()},o.collapse=function(){p()},o.toggle=function(){e?p():u()},o.cursor="default",o.color=o.backgroundColor,o.height=`calc(100% - ${o.topBarHeight}px)`,o.width=40,o.bottom=0,o.left=0,o.round=0;o.scrollableBox=startBox(0,30,o.expandedWidth,0),that.color="transparent",that.scrollY=1,o.topBox=VGroup({align:"top left",gap:0,padding:0,height:"auto",width:"100%"}),that.position="relative",o.items.forEach(t=>{o.addItemToTop(t)}),endGroup(),endBox(),o.scrollBar=ScrollBar({scrollableBox:o.scrollableBox,bar_border:0,bar_round:3,bar_borderColor:"rgba(0, 0, 0, 1)",bar_width:4,bar_mouseOverWidth:4,bar_mouseOverColor:"#FFFFFF",bar_opacity:.4,bar_mouseOverOpacity:.9,bar_padding:2,bar_color:"#FFFFFF",neverHide:0,showDots:1});const f=function(){o.scrollableBox.height=o.height-60-o.bottomBox.height-30};return o.bottomBox=VGroup({align:"bottom left",gap:0,padding:0,height:"auto",width:o.expandedWidth}),that.bottom=30,that.left=0,that.color="transparent",o.bottomBox.onResize(function(t){f()}),page.onResize(f),endGroup(),o.setOpenOnClick(o.openOnClick),o.on("mouseenter",function(){r||u()}),o.on("mouseleave",function(){r||p()}),o.on("click",function(){r&&!e&&u()}),o.listenTo(document,"pointerdown",function(t,n){o&&r&&e&&(o.elem.contains(n.target)||p())},!0),endObject(o)};
2
+ "use strict";const LeftMenuDefaults={key:"0",expandedWidth:250,itemHeight:40,topBarHeight:40,backgroundColor:"#141414",hoverColor:"rgba(255, 255, 255, 0.05)",selectedColor:"#583432",titleColor:"#8E342F",textColor:"rgba(255, 255, 255, 0.6)",selectedTextColor:"rgba(255, 255, 255, 0.95)",invertIconColor:1,openOnClick:"auto",items:[],onItemClick:function(t){},onMenuToggle:function(t){}},LeftMenu=function(t={}){mergeIntoIfMissing(t,LeftMenuDefaults);let o=startObject(t),e=0,n=null,r=0;const i=[],a=[];o.publicVar=1,o.state="collapsed";const c=function(t,e){if("normal"===e)return t.css.background="transparent",t.icon.opacity=.6,void(t.textLabel.textColor=o.textColor);const n="selected"===e?o.selectedColor:o.hoverColor;t.css.background=`linear-gradient(to right, ${n} 0%, rgba(0,0,0,0) 100%)`,t.icon.opacity=1,t.textLabel.textColor=o.selectedTextColor},l=function(t){const i=startBox({width:"100%",height:o.itemHeight,color:"transparent",clickable:1,position:"relative"});return i.setMotion("background-color 0.2s"),i.cursor="pointer",i.data=t,HGroup({align:"left center",gap:20,padding:[8,0]}),i.icon=Icon({width:24,height:24,color:"transparent",opacity:.6}),i.icon.load(t.icon),1==o.invertIconColor&&(that.css.filter="invert(100%)"),i.textLabel=Label({text:t.text,textColor:o.textColor,fontSize:18,color:"transparent"}),endGroup(),endBox(),i.on("click",function(i,a){a&&a.stopPropagation(),!r||e||"direct"===o.openOnClick?(n!=t.key&&(t.dontSelect||s(t.key),o.onItemClick(t)),r&&p()):u()}),i.on("mouseover",function(){r||n!=t.key&&c(i,"hover")}),i.on("mouseout",function(){r||n!=t.key&&c(i,"normal")}),i},d=function(t){const e=startBox({width:"100%",height:29,color:"transparent",clickable:1,position:"relative"});e.data=t,Box(0,0,100,1,{color:o.titleColor}),that.top=14,that.opacity=.5,AutoLayout({align:"left center",padding:[40,0]});return Label({text:t.text,textColor:o.titleColor,fontSize:12,color:o.backgroundColor,padding:[12,0]}).css={fontWeight:"bold",textTransform:"uppercase"},endAutoLayout(),endBox(),e};o.clearSelection=function(){if(n){const t=a.find(t=>t.data.key===n);t&&"button"===t.data.type&&(c(t,"normal"),t.cursor="pointer"),n=null}};const s=function(t){o.clearSelection();const e=a.find(o=>o.data.key===t);e&&"button"===e.data.type&&(c(e,"selected"),e.cursor="default",n=t)},u=function(){e||(e=1,o.state="expanded",o.width=o.expandedWidth,o.onMenuToggle(1))},p=function(){e&&(e=0,o.state="collapsed",o.width=40,o.onMenuToggle(0))};o.setOpenOnClick=function(t){return o.openOnClick=t,r="auto"===t?window.matchMedia&&window.matchMedia("(hover: none)").matches||window.matchMedia&&window.matchMedia("(pointer: coarse)").matches?1:basic.isMobile():"direct"===t||basic.isOn(t)?1:0,r||p(),r},o.isTapMode=function(){return r};const h=o.remove;o.superRemove=h,o.remove=function(){o&&(page.remove_onResize(f),h.call(o),o=null)},o.addItemToTop=function(t){i.push(t);const e="button"===t.type?l(t):d(t);return a.push(e),o.topBox.add(e),e},o.addItemToBottom=function(t){i.push(t);const e="button"===t.type?l(t):d(t);return a.push(e),o.bottomBox.add(e),e},o.removeItem=function(t){t===n&&o.clearSelection();const e=i.findIndex(o=>o.key===t);if(-1!==e){a[e].remove(),i.splice(e,1),a.splice(e,1)}},o.getSelectedItem=function(){return i.find(t=>t.key===n)},o.setSelectedItem=function(t){s(t)},o.expand=function(){u()},o.collapse=function(){p()},o.toggle=function(){e?p():u()},o.cursor="default",o.color=o.backgroundColor,o.height=`calc(100% - ${o.topBarHeight}px)`,o.width=40,o.bottom=0,o.left=0,o.round=0;o.scrollableBox=startBox(0,30,o.expandedWidth,0),that.color="transparent",that.scrollY=1,o.topBox=VGroup({align:"top left",gap:0,padding:0,height:"auto",width:"100%"}),that.position="relative",o.items.forEach(t=>{o.addItemToTop(t)}),endGroup(),endBox(),o.scrollBar=ScrollBar({scrollableBox:o.scrollableBox,bar_border:0,bar_round:3,bar_borderColor:"rgba(0, 0, 0, 1)",bar_width:4,bar_mouseOverWidth:4,bar_mouseOverColor:"#FFFFFF",bar_opacity:.4,bar_mouseOverOpacity:.9,bar_padding:2,bar_color:"#FFFFFF",neverHide:0,showDots:1});const f=function(){o.scrollableBox.height=o.height-60-o.bottomBox.height-30};return o.bottomBox=VGroup({align:"bottom left",gap:0,padding:0,height:"auto",width:o.expandedWidth}),that.bottom=30,that.left=0,that.color="transparent",o.bottomBox.onResize(function(t){f()}),page.onResize(f),endGroup(),o.setOpenOnClick(o.openOnClick),o.on("mouseenter",function(){r||u()}),o.on("mouseleave",function(){r||p()}),o.on("click",function(){r&&!e&&"direct"!==o.openOnClick&&u()}),o.listenTo(document,"pointerdown",function(t,n){o&&r&&e&&(o.elem.contains(n.target)||p())},!0),endObject(o)};
@@ -102,6 +102,7 @@
102
102
  // Ekran bu değerden genişse panel normal boyutta görünür (zoom 1).
103
103
  // Daha dar ekranlarda, yerleşim bozulmasın diye panelin tamamı küçülür (zoom out).
104
104
  const PAGE_FIT_WIDTH = 650;
105
+ const FINGER_HEIGHT = 44; // px on the screen: a row of the left menu that a finger can hit
105
106
 
106
107
  // NOTE: page.fit(650) -> ekran >= 650px ise zoom 1, değilse zoom = ekranGenisligi / 650.
107
108
  const fitPageWidth = function() {
@@ -239,7 +240,10 @@
239
240
  // Left Menu
240
241
  // WHY: The menu keeps its own default look (dark, red selection) in every theme, so
241
242
  // it reads its own ink keys instead of Ink()/T.invertIcon, which follow the page.
243
+ // WHY: page.fit() zooms the page: on a phone the 40 px rows of the menu were 24 px high on the screen.
244
+ const isTouchScreen = window.matchMedia("(hover: none)").matches;
242
245
  window.leftMenu = LeftMenu({
246
+ itemHeight: isTouchScreen ? Math.max(40, Math.round(FINGER_HEIGHT / page.zoom)) : 40,
243
247
  backgroundColor: T.menu,
244
248
  selectedColor: T.menuSelected,
245
249
  titleColor: T.menuTitle,