@bbki.ng/components 1.5.50 → 2.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.
package/dist/index.js CHANGED
@@ -1070,7 +1070,7 @@ var import_react23 = __toESM(require("react"));
1070
1070
 
1071
1071
  // src/loading-spiral/createSettings.ts
1072
1072
  var createSettings = (settings) => {
1073
- const { canvas, step = 0.1 } = settings;
1073
+ const { canvas, step = 0.09 } = settings;
1074
1074
  const uniforms = {
1075
1075
  uProgress: {
1076
1076
  type: "float",
@@ -1079,6 +1079,7 @@ var createSettings = (settings) => {
1079
1079
  };
1080
1080
  return {
1081
1081
  uniforms,
1082
+ devicePixelRatio: window.devicePixelRatio,
1082
1083
  shouldRender: true,
1083
1084
  canvas,
1084
1085
  onRender: (r) => {
@@ -1090,14 +1091,38 @@ var createSettings = (settings) => {
1090
1091
 
1091
1092
  // src/loading-spiral/constants.ts
1092
1093
  var VERTEX_SHADER = `
1093
- attribute vec3 ${"aPositionStart" /* POSITION_START */};
1094
1094
  attribute vec3 ${"aColor" /* COLOR */};
1095
1095
  attribute float ${"aOffsetY" /* OFFSET_Y */};
1096
+ attribute float ${"aPercent" /* PERCENT */};
1097
+ attribute float ${"aLength" /* LENGTH */};
1098
+ attribute float ${"aPointSize" /* POINT_SIZE */};
1099
+
1096
1100
  uniform mat4 uProjectionMatrix;
1097
1101
  uniform mat4 uModelMatrix;
1098
1102
  uniform mat4 uViewMatrix;
1099
1103
  uniform float uProgress;
1104
+
1100
1105
  varying vec3 vColor;
1106
+
1107
+ vec3 curve(float _percent, float _length) {
1108
+ const float PI2 = 3.141592653589793 * 2.0;
1109
+ float radius = 0.028 / 0.15 * _length;
1110
+
1111
+ float t = mod(_percent, 0.25) / 0.25;
1112
+ t = mod(_percent, 0.25) - (2.0 * (1.0 - t) * t * -0.0185 + t * t * 0.25);
1113
+ float x = _length * sin(PI2 * _percent);
1114
+ float y = radius * cos(PI2 * 3.0 * _percent);
1115
+
1116
+ if (
1117
+ floor(_percent / 0.25) == 0.0
1118
+ || floor(_percent / 0.25) == 2.0
1119
+ ) {
1120
+ t = t * -1.0;
1121
+ }
1122
+ float z = radius * sin(PI2 * 2.0 * (_percent - t));
1123
+ return vec3(x, y, z);
1124
+ }
1125
+
1101
1126
  mat4 rotateX(float _angle){
1102
1127
  return mat4(
1103
1128
  1.0, 0.0, 0.0, 0.0,
@@ -1106,22 +1131,7 @@ var VERTEX_SHADER = `
1106
1131
  0.0, 0.0, 0.0, 1.0
1107
1132
  );
1108
1133
  }
1109
- mat4 rotateY(float _angle){
1110
- return mat4(
1111
- cos(_angle), 0.0, sin(_angle), 0.0,
1112
- 0.0, 1.0, 0.0, 0.0,
1113
- -sin(_angle), 0.0, cos(_angle), 0.0,
1114
- 0.0, 0.0, 0.0, 1.0
1115
- );
1116
- }
1117
- mat4 rotateZ(float _angle){
1118
- return mat4(
1119
- cos(_angle), -sin(_angle), 0.0, 0.0,
1120
- sin(_angle), cos(_angle), 0.0, 0.0,
1121
- 0.0, 0.0, 1.0, 0.0,
1122
- 0.0, 0.0, 0.0, 1.0
1123
- );
1124
- }
1134
+
1125
1135
  mat4 translateY(float _offset){
1126
1136
  return mat4(
1127
1137
  1.0, 0.0, 0.0, 0.0,
@@ -1130,16 +1140,22 @@ var VERTEX_SHADER = `
1130
1140
  0.0, 0.0, 0.0, 1.0
1131
1141
  );
1132
1142
  }
1143
+
1133
1144
  void main(){
1134
- gl_Position = uProjectionMatrix * uModelMatrix * uViewMatrix * rotateX(uProgress) * vec4(${"aPositionStart" /* POSITION_START */}, 1.0) * translateY(${"aOffsetY" /* OFFSET_Y */});
1135
- gl_PointSize = 1.0;
1145
+ gl_Position = uProjectionMatrix
1146
+ * uModelMatrix
1147
+ * uViewMatrix
1148
+ * rotateX(uProgress)
1149
+ * vec4(curve(${"aPercent" /* PERCENT */}, ${"aLength" /* LENGTH */}), 1.0)
1150
+ * translateY(${"aOffsetY" /* OFFSET_Y */});
1151
+
1152
+ gl_PointSize = ${"aPointSize" /* POINT_SIZE */};
1136
1153
  vColor = ${"aColor" /* COLOR */};
1137
1154
  }
1138
1155
  `;
1139
1156
  var FRAGMENT_SHADER = `
1140
1157
  precision mediump float;
1141
1158
  uniform float uProgress;
1142
-
1143
1159
  varying vec3 vColor;
1144
1160
  void main(){
1145
1161
  gl_FragColor = vec4(vColor, 1.0);
@@ -1154,30 +1170,23 @@ var rgba = (val) => {
1154
1170
 
1155
1171
  // src/loading-spiral/createOptions.ts
1156
1172
  var DEFAULT_OPT = {
1157
- multiplier: 5e4,
1173
+ multiplier: 5e3,
1158
1174
  color: [209, 213, 219, 1],
1159
1175
  offset: -0.3,
1160
- length: 0.15
1176
+ length: 0.3
1161
1177
  };
1162
1178
  var createOptions = (opt = DEFAULT_OPT) => {
1163
1179
  const { multiplier, color, length, offset = -1 * 0.3 } = opt;
1164
- const radius = 0.028 / 0.15 * length;
1165
1180
  const attributes = [
1166
1181
  {
1167
- name: "aPositionStart" /* POSITION_START */,
1168
- data: (index, total) => {
1169
- const percent = index / total;
1170
- const pi2 = Math.PI * 2;
1171
- let x = length * Math.sin(pi2 * percent), y = radius * Math.cos(pi2 * 3 * percent), z, t;
1172
- t = percent % 0.25 / 0.25;
1173
- t = percent % 0.25 - (2 * (1 - t) * t * -0.0185 + t * t * 0.25);
1174
- if (Math.floor(percent / 0.25) == 0 || Math.floor(percent / 0.25) == 2) {
1175
- t *= -1;
1176
- }
1177
- z = radius * Math.sin(pi2 * 2 * (percent - t));
1178
- return [x, y, z];
1179
- },
1180
- size: 3
1182
+ name: "aPercent" /* PERCENT */,
1183
+ data: (i, total) => [i / total],
1184
+ size: 1
1185
+ },
1186
+ {
1187
+ name: "aLength" /* LENGTH */,
1188
+ data: () => [length],
1189
+ size: 1
1181
1190
  },
1182
1191
  {
1183
1192
  name: "aColor" /* COLOR */,
@@ -1188,6 +1197,11 @@ var createOptions = (opt = DEFAULT_OPT) => {
1188
1197
  name: "aOffsetY" /* OFFSET_Y */,
1189
1198
  data: () => [offset],
1190
1199
  size: 1
1200
+ },
1201
+ {
1202
+ name: "aPointSize" /* POINT_SIZE */,
1203
+ data: () => [window.devicePixelRatio * 1.5],
1204
+ size: 1
1191
1205
  }
1192
1206
  ];
1193
1207
  return {
@@ -1209,7 +1223,7 @@ var useResizedCanvasRef = (maxSize) => {
1209
1223
  if (!canvas || !container)
1210
1224
  return;
1211
1225
  const { width, height } = container.getBoundingClientRect();
1212
- const canvasSize = Math.max(width, height);
1226
+ const canvasSize = Math.min(width, height);
1213
1227
  const size = Math.min(canvasSize, maxSize);
1214
1228
  canvas.setAttribute("width", `${size}`);
1215
1229
  canvas.setAttribute("height", `${size}`);
@@ -1231,19 +1245,15 @@ var LoadingSpiral = (props) => {
1231
1245
  const phenomenon = new import_phenomenon.default({
1232
1246
  settings: createSettings({ canvas: canvasRef.current, step }),
1233
1247
  context: {
1234
- alpha: true,
1235
1248
  antialias: true
1236
1249
  }
1237
1250
  });
1238
1251
  phenomenon.add("spiral", createOptions(Object.assign({}, DEFAULT_OPT, rest)));
1239
1252
  }, []);
1240
- return /* @__PURE__ */ import_react23.default.createElement("div", {
1241
- className: (0, import_classnames13.default)("h-full w-full overflow-hidden flex justify-center items-center", className),
1242
- ref: containerRef
1243
- }, /* @__PURE__ */ import_react23.default.createElement("canvas", {
1253
+ return /* @__PURE__ */ import_react23.default.createElement("canvas", {
1244
1254
  ref: canvasRef,
1245
- className: "relative"
1246
- }));
1255
+ className: (0, import_classnames13.default)("h-full w-full overflow-hidden flex justify-center items-center", className)
1256
+ });
1247
1257
  };
1248
1258
  module.exports = __toCommonJS(src_exports);
1249
1259
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.mjs CHANGED
@@ -1011,7 +1011,7 @@ import React21, { useEffect as useEffect4 } from "react";
1011
1011
 
1012
1012
  // src/loading-spiral/createSettings.ts
1013
1013
  var createSettings = (settings) => {
1014
- const { canvas, step = 0.1 } = settings;
1014
+ const { canvas, step = 0.09 } = settings;
1015
1015
  const uniforms = {
1016
1016
  uProgress: {
1017
1017
  type: "float",
@@ -1020,6 +1020,7 @@ var createSettings = (settings) => {
1020
1020
  };
1021
1021
  return {
1022
1022
  uniforms,
1023
+ devicePixelRatio: window.devicePixelRatio,
1023
1024
  shouldRender: true,
1024
1025
  canvas,
1025
1026
  onRender: (r) => {
@@ -1031,14 +1032,38 @@ var createSettings = (settings) => {
1031
1032
 
1032
1033
  // src/loading-spiral/constants.ts
1033
1034
  var VERTEX_SHADER = `
1034
- attribute vec3 ${"aPositionStart" /* POSITION_START */};
1035
1035
  attribute vec3 ${"aColor" /* COLOR */};
1036
1036
  attribute float ${"aOffsetY" /* OFFSET_Y */};
1037
+ attribute float ${"aPercent" /* PERCENT */};
1038
+ attribute float ${"aLength" /* LENGTH */};
1039
+ attribute float ${"aPointSize" /* POINT_SIZE */};
1040
+
1037
1041
  uniform mat4 uProjectionMatrix;
1038
1042
  uniform mat4 uModelMatrix;
1039
1043
  uniform mat4 uViewMatrix;
1040
1044
  uniform float uProgress;
1045
+
1041
1046
  varying vec3 vColor;
1047
+
1048
+ vec3 curve(float _percent, float _length) {
1049
+ const float PI2 = 3.141592653589793 * 2.0;
1050
+ float radius = 0.028 / 0.15 * _length;
1051
+
1052
+ float t = mod(_percent, 0.25) / 0.25;
1053
+ t = mod(_percent, 0.25) - (2.0 * (1.0 - t) * t * -0.0185 + t * t * 0.25);
1054
+ float x = _length * sin(PI2 * _percent);
1055
+ float y = radius * cos(PI2 * 3.0 * _percent);
1056
+
1057
+ if (
1058
+ floor(_percent / 0.25) == 0.0
1059
+ || floor(_percent / 0.25) == 2.0
1060
+ ) {
1061
+ t = t * -1.0;
1062
+ }
1063
+ float z = radius * sin(PI2 * 2.0 * (_percent - t));
1064
+ return vec3(x, y, z);
1065
+ }
1066
+
1042
1067
  mat4 rotateX(float _angle){
1043
1068
  return mat4(
1044
1069
  1.0, 0.0, 0.0, 0.0,
@@ -1047,22 +1072,7 @@ var VERTEX_SHADER = `
1047
1072
  0.0, 0.0, 0.0, 1.0
1048
1073
  );
1049
1074
  }
1050
- mat4 rotateY(float _angle){
1051
- return mat4(
1052
- cos(_angle), 0.0, sin(_angle), 0.0,
1053
- 0.0, 1.0, 0.0, 0.0,
1054
- -sin(_angle), 0.0, cos(_angle), 0.0,
1055
- 0.0, 0.0, 0.0, 1.0
1056
- );
1057
- }
1058
- mat4 rotateZ(float _angle){
1059
- return mat4(
1060
- cos(_angle), -sin(_angle), 0.0, 0.0,
1061
- sin(_angle), cos(_angle), 0.0, 0.0,
1062
- 0.0, 0.0, 1.0, 0.0,
1063
- 0.0, 0.0, 0.0, 1.0
1064
- );
1065
- }
1075
+
1066
1076
  mat4 translateY(float _offset){
1067
1077
  return mat4(
1068
1078
  1.0, 0.0, 0.0, 0.0,
@@ -1071,16 +1081,22 @@ var VERTEX_SHADER = `
1071
1081
  0.0, 0.0, 0.0, 1.0
1072
1082
  );
1073
1083
  }
1084
+
1074
1085
  void main(){
1075
- gl_Position = uProjectionMatrix * uModelMatrix * uViewMatrix * rotateX(uProgress) * vec4(${"aPositionStart" /* POSITION_START */}, 1.0) * translateY(${"aOffsetY" /* OFFSET_Y */});
1076
- gl_PointSize = 1.0;
1086
+ gl_Position = uProjectionMatrix
1087
+ * uModelMatrix
1088
+ * uViewMatrix
1089
+ * rotateX(uProgress)
1090
+ * vec4(curve(${"aPercent" /* PERCENT */}, ${"aLength" /* LENGTH */}), 1.0)
1091
+ * translateY(${"aOffsetY" /* OFFSET_Y */});
1092
+
1093
+ gl_PointSize = ${"aPointSize" /* POINT_SIZE */};
1077
1094
  vColor = ${"aColor" /* COLOR */};
1078
1095
  }
1079
1096
  `;
1080
1097
  var FRAGMENT_SHADER = `
1081
1098
  precision mediump float;
1082
1099
  uniform float uProgress;
1083
-
1084
1100
  varying vec3 vColor;
1085
1101
  void main(){
1086
1102
  gl_FragColor = vec4(vColor, 1.0);
@@ -1095,30 +1111,23 @@ var rgba = (val) => {
1095
1111
 
1096
1112
  // src/loading-spiral/createOptions.ts
1097
1113
  var DEFAULT_OPT = {
1098
- multiplier: 5e4,
1114
+ multiplier: 5e3,
1099
1115
  color: [209, 213, 219, 1],
1100
1116
  offset: -0.3,
1101
- length: 0.15
1117
+ length: 0.3
1102
1118
  };
1103
1119
  var createOptions = (opt = DEFAULT_OPT) => {
1104
1120
  const { multiplier, color, length, offset = -1 * 0.3 } = opt;
1105
- const radius = 0.028 / 0.15 * length;
1106
1121
  const attributes = [
1107
1122
  {
1108
- name: "aPositionStart" /* POSITION_START */,
1109
- data: (index, total) => {
1110
- const percent = index / total;
1111
- const pi2 = Math.PI * 2;
1112
- let x = length * Math.sin(pi2 * percent), y = radius * Math.cos(pi2 * 3 * percent), z, t;
1113
- t = percent % 0.25 / 0.25;
1114
- t = percent % 0.25 - (2 * (1 - t) * t * -0.0185 + t * t * 0.25);
1115
- if (Math.floor(percent / 0.25) == 0 || Math.floor(percent / 0.25) == 2) {
1116
- t *= -1;
1117
- }
1118
- z = radius * Math.sin(pi2 * 2 * (percent - t));
1119
- return [x, y, z];
1120
- },
1121
- size: 3
1123
+ name: "aPercent" /* PERCENT */,
1124
+ data: (i, total) => [i / total],
1125
+ size: 1
1126
+ },
1127
+ {
1128
+ name: "aLength" /* LENGTH */,
1129
+ data: () => [length],
1130
+ size: 1
1122
1131
  },
1123
1132
  {
1124
1133
  name: "aColor" /* COLOR */,
@@ -1129,6 +1138,11 @@ var createOptions = (opt = DEFAULT_OPT) => {
1129
1138
  name: "aOffsetY" /* OFFSET_Y */,
1130
1139
  data: () => [offset],
1131
1140
  size: 1
1141
+ },
1142
+ {
1143
+ name: "aPointSize" /* POINT_SIZE */,
1144
+ data: () => [window.devicePixelRatio * 1.5],
1145
+ size: 1
1132
1146
  }
1133
1147
  ];
1134
1148
  return {
@@ -1150,7 +1164,7 @@ var useResizedCanvasRef = (maxSize) => {
1150
1164
  if (!canvas || !container)
1151
1165
  return;
1152
1166
  const { width, height } = container.getBoundingClientRect();
1153
- const canvasSize = Math.max(width, height);
1167
+ const canvasSize = Math.min(width, height);
1154
1168
  const size = Math.min(canvasSize, maxSize);
1155
1169
  canvas.setAttribute("width", `${size}`);
1156
1170
  canvas.setAttribute("height", `${size}`);
@@ -1172,19 +1186,15 @@ var LoadingSpiral = (props) => {
1172
1186
  const phenomenon = new Phenomenon({
1173
1187
  settings: createSettings({ canvas: canvasRef.current, step }),
1174
1188
  context: {
1175
- alpha: true,
1176
1189
  antialias: true
1177
1190
  }
1178
1191
  });
1179
1192
  phenomenon.add("spiral", createOptions(Object.assign({}, DEFAULT_OPT, rest)));
1180
1193
  }, []);
1181
- return /* @__PURE__ */ React21.createElement("div", {
1182
- className: classNames7("h-full w-full overflow-hidden flex justify-center items-center", className),
1183
- ref: containerRef
1184
- }, /* @__PURE__ */ React21.createElement("canvas", {
1194
+ return /* @__PURE__ */ React21.createElement("canvas", {
1185
1195
  ref: canvasRef,
1186
- className: "relative"
1187
- }));
1196
+ className: classNames7("h-full w-full overflow-hidden flex justify-center items-center", className)
1197
+ });
1188
1198
  };
1189
1199
  export {
1190
1200
  Article,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbki.ng/components",
3
- "version": "1.5.50",
3
+ "version": "2.0.0",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",