widget-iccandle 0.0.2 → 0.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/README.md CHANGED
@@ -1,3 +1,57 @@
1
+ # widget-iccandle
2
+
3
+ React wrapper that mounts the TradingView Charting Library widget.
4
+
5
+ ## Partner usage (React)
6
+
7
+ 1) Install:
8
+
9
+ ```bash
10
+ npm i widget-iccandle
11
+ ```
12
+
13
+ 2) Host TradingView assets in your app (required):
14
+
15
+ - Put the TradingView **Charting Library** folder at: `public/charting_library/`
16
+ - Put the **UDF datafeed bundle** at: `public/datafeeds/udf/dist/bundle.js`
17
+
18
+ If you want to copy them from this npm package:
19
+
20
+ ```bash
21
+ mkdir -p public
22
+ cp -R node_modules/widget-iccandle/dist/charting_library public/charting_library
23
+ cp -R node_modules/widget-iccandle/dist/datafeeds public/datafeeds
24
+ ```
25
+
26
+ So these URLs work in the browser:
27
+
28
+ - `/charting_library/charting_library.js`
29
+ - `/datafeeds/udf/dist/bundle.js`
30
+
31
+ 3) Use the component:
32
+
33
+ ```tsx
34
+ import { TradingViewWidget } from "widget-iccandle";
35
+
36
+ export function Chart() {
37
+ return (
38
+ <div style={{ width: "100%", height: 600 }}>
39
+ <TradingViewWidget
40
+ libraryPath="/charting_library/"
41
+ udfBundleUrl="/datafeeds/udf/dist/bundle.js"
42
+ datafeedUrl="https://demo_feed.tradingview.com"
43
+ symbol="AAPL"
44
+ interval="D"
45
+ />
46
+ </div>
47
+ );
48
+ }
49
+ ```
50
+
51
+ ## Next.js note
52
+
53
+ This component uses `window` and must run on the client. Use it in a Client Component (`"use client"`) or via dynamic import with `ssr: false`.
54
+
1
55
  # React + TypeScript + Vite
2
56
 
3
57
  This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
package/dist/index.cjs ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("react");var F={exports:{}},O={};var B;function ae(){if(B)return O;B=1;var t=Symbol.for("react.transitional.element"),c=Symbol.for("react.fragment");function l(f,i,s){var u=null;if(s!==void 0&&(u=""+s),i.key!==void 0&&(u=""+i.key),"key"in i){s={};for(var d in i)d!=="key"&&(s[d]=i[d])}else s=i;return i=s.ref,{$$typeof:t,type:f,key:u,ref:i!==void 0?i:null,props:s}}return O.Fragment=c,O.jsx=l,O.jsxs=l,O}var x={};var H;function oe(){return H||(H=1,process.env.NODE_ENV!=="production"&&(function(){function t(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===$?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case p:return"Fragment";case M:return"Profiler";case W:return"StrictMode";case P:return"Suspense";case D:return"SuspenseList";case w:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case C:return"Portal";case y:return e.displayName||"Context";case N:return(e._context.displayName||"Context")+".Consumer";case k:var r=e.render;return e=e.displayName,e||(e=r.displayName||r.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case L:return r=e.displayName||null,r!==null?r:t(e.type)||"Memo";case S:r=e._payload,e=e._init;try{return t(e(r))}catch{}}return null}function c(e){return""+e}function l(e){try{c(e);var r=!1}catch{r=!0}if(r){r=console;var n=r.error,a=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return n.call(r,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",a),c(e)}}function f(e){if(e===p)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===S)return"<...>";try{var r=t(e);return r?"<"+r+">":"<...>"}catch{return"<...>"}}function i(){var e=A.A;return e===null?null:e.getOwner()}function s(){return Error("react-stack-top-frame")}function u(e){if(v.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function d(e,r){function n(){q||(q=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",r))}n.isReactWarning=!0,Object.defineProperty(e,"key",{get:n,configurable:!0})}function m(){var e=t(this.type);return z[e]||(z[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function _(e,r,n,a,Y,U){var o=n.ref;return e={$$typeof:h,type:e,key:r,props:n,_owner:a},(o!==void 0?o:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:m}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:Y}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:U}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function R(e,r,n,a,Y,U){var o=r.children;if(o!==void 0)if(a)if(te(o)){for(a=0;a<o.length;a++)g(o[a]);Object.freeze&&Object.freeze(o)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else g(o);if(v.call(r,"key")){o=t(e);var b=Object.keys(r).filter(function(ne){return ne!=="key"});a=0<b.length?"{key: someKey, "+b.join(": ..., ")+": ...}":"{key: someKey}",X[o+a]||(b=0<b.length?"{"+b.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
2
+ let props = %s;
3
+ <%s {...props} />
4
+ React keys must be passed directly to JSX without using spread:
5
+ let props = %s;
6
+ <%s key={someKey} {...props} />`,a,o,b,o),X[o+a]=!0)}if(o=null,n!==void 0&&(l(n),o=""+n),u(r)&&(l(r.key),o=""+r.key),"key"in r){n={};for(var V in r)V!=="key"&&(n[V]=r[V])}else n=r;return o&&d(n,typeof e=="function"?e.displayName||e.name||"Unknown":e),_(e,o,n,i(),Y,U)}function g(e){T(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===S&&(e._payload.status==="fulfilled"?T(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function T(e){return typeof e=="object"&&e!==null&&e.$$typeof===h}var E=j,h=Symbol.for("react.transitional.element"),C=Symbol.for("react.portal"),p=Symbol.for("react.fragment"),W=Symbol.for("react.strict_mode"),M=Symbol.for("react.profiler"),N=Symbol.for("react.consumer"),y=Symbol.for("react.context"),k=Symbol.for("react.forward_ref"),P=Symbol.for("react.suspense"),D=Symbol.for("react.suspense_list"),L=Symbol.for("react.memo"),S=Symbol.for("react.lazy"),w=Symbol.for("react.activity"),$=Symbol.for("react.client.reference"),A=E.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,v=Object.prototype.hasOwnProperty,te=Array.isArray,I=console.createTask?console.createTask:function(){return null};E={react_stack_bottom_frame:function(e){return e()}};var q,z={},J=E.react_stack_bottom_frame.bind(E,s)(),G=I(f(s)),X={};x.Fragment=p,x.jsx=function(e,r,n){var a=1e4>A.recentlyCreatedOwnerStacks++;return R(e,r,n,!1,a?Error("react-stack-top-frame"):J,a?I(f(e)):G)},x.jsxs=function(e,r,n){var a=1e4>A.recentlyCreatedOwnerStacks++;return R(e,r,n,!0,a?Error("react-stack-top-frame"):J,a?I(f(e)):G)}})()),x}var Z;function ie(){return Z||(Z=1,process.env.NODE_ENV==="production"?F.exports=ae():F.exports=oe()),F.exports}var se=ie();const Q=new Map;function re(){return typeof window<"u"&&typeof document<"u"}function K(t){if(!re())return Promise.resolve();const c=Q.get(t);if(c)return c;const l=new Promise((f,i)=>{const s=document.querySelector(`script[src="${t}"]`);if(s?.dataset.loaded==="true"){f();return}const u=s??document.createElement("script");u.src=t,u.async=!0;const d=()=>{u.dataset.loaded="true",_(),f()},m=()=>{_(),i(new Error(`Failed to load script: ${t}`))},_=()=>{u.removeEventListener("load",d),u.removeEventListener("error",m)};u.addEventListener("load",d),u.addEventListener("error",m),s||document.head.appendChild(u)});return Q.set(t,l),l}async function ee(t,{timeoutMs:c=15e3,intervalMs:l=50}={}){if(!re())return;const f=Date.now();for(;;){if(t())return;if(Date.now()-f>c)throw new Error("Timed out waiting for condition.");await new Promise(i=>setTimeout(i,l))}}function ue(t){return t.endsWith("/")?t:`${t}/`}function ce(){if(typeof location>"u")return null;const c=new RegExp("[\\?&]lang=([^&#]*)").exec(location.search);return c===null?null:decodeURIComponent(c[1].replace(/\+/g," "))}function le({libraryPath:t="/charting_library/",chartingLibraryScriptUrl:c,udfBundleUrl:l="/datafeeds/udf/dist/bundle.js",datafeedUrl:f="https://demo_feed.tradingview.com",symbol:i="AAPL",interval:s="D",locale:u,autosize:d=!0,fullscreen:m=!1,disabledFeatures:_=["use_localstorage_for_settings"],enabledFeatures:R=["study_templates"],chartsStorageUrl:g="https://saveload.tradingview.com",chartsStorageApiVersion:T="1.1",clientId:E="tradingview.com",userId:h="public_user_id",studiesOverrides:C={},widgetOptions:p,className:W,style:M,onReady:N}){const y=j.useRef(null),k=j.useRef(null),P=j.useMemo(()=>ue(t),[t]),D=c??`${P}charting_library.js`;return j.useEffect(()=>{let L=!1;async function S(){if(!y.current||typeof window>"u"||(await K(D),await ee(()=>!!window.TradingView?.widget),l&&(await K(l),await ee(()=>!!window.Datafeeds?.UDFCompatibleDatafeed)),L))return;const w=window.TradingView?.widget;if(!w)throw new Error("TradingView widget constructor not found. Make sure the Charting Library script is reachable.");const $=p?.datafeed??(window.Datafeeds?.UDFCompatibleDatafeed?new window.Datafeeds.UDFCompatibleDatafeed(f):void 0);if(!$)throw new Error("No datafeed available. Provide `udfBundleUrl` (to load UDF) or pass `widgetOptions.datafeed`.");const A={symbol:i,interval:s,container:y.current,library_path:P,locale:u??ce()??"en",datafeed:$,disabled_features:_,enabled_features:R,charts_storage_url:g,charts_storage_api_version:T,client_id:E,user_id:h,fullscreen:m,autosize:d,studies_overrides:C,...p},v=new w(A);k.current=v,v.onChartReady(()=>{N?.(v)})}return S().catch(w=>{console.error(w)}),()=>{L=!0,k.current?.remove(),k.current=null}},[D,l,f,P,i,s,u,d,m,g,T,E,h,_,R,C,p,N]),se.jsx("div",{ref:y,className:W,style:{width:"100%",height:"100%",...M}})}exports.TradingViewWidget=le;
@@ -0,0 +1,3 @@
1
+ export { TradingViewWidget } from "./tradingview/TradingViewWidget";
2
+ export type { TradingViewWidgetProps, TradingViewWidgetOptions, } from "./tradingview/types";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,YAAY,EACV,sBAAsB,EACtB,wBAAwB,GACzB,MAAM,qBAAqB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,408 @@
1
+ import oe, { useRef as X, useMemo as ae, useEffect as ie } from "react";
2
+ var Y = { exports: {} }, O = {};
3
+ var B;
4
+ function se() {
5
+ if (B) return O;
6
+ B = 1;
7
+ var t = /* @__PURE__ */ Symbol.for("react.transitional.element"), c = /* @__PURE__ */ Symbol.for("react.fragment");
8
+ function l(f, i, s) {
9
+ var u = null;
10
+ if (s !== void 0 && (u = "" + s), i.key !== void 0 && (u = "" + i.key), "key" in i) {
11
+ s = {};
12
+ for (var d in i)
13
+ d !== "key" && (s[d] = i[d]);
14
+ } else s = i;
15
+ return i = s.ref, {
16
+ $$typeof: t,
17
+ type: f,
18
+ key: u,
19
+ ref: i !== void 0 ? i : null,
20
+ props: s
21
+ };
22
+ }
23
+ return O.Fragment = c, O.jsx = l, O.jsxs = l, O;
24
+ }
25
+ var S = {};
26
+ var H;
27
+ function ue() {
28
+ return H || (H = 1, process.env.NODE_ENV !== "production" && (function() {
29
+ function t(e) {
30
+ if (e == null) return null;
31
+ if (typeof e == "function")
32
+ return e.$$typeof === L ? null : e.displayName || e.name || null;
33
+ if (typeof e == "string") return e;
34
+ switch (e) {
35
+ case E:
36
+ return "Fragment";
37
+ case W:
38
+ return "Profiler";
39
+ case F:
40
+ return "StrictMode";
41
+ case P:
42
+ return "Suspense";
43
+ case N:
44
+ return "SuspenseList";
45
+ case w:
46
+ return "Activity";
47
+ }
48
+ if (typeof e == "object")
49
+ switch (typeof e.tag == "number" && console.error(
50
+ "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
51
+ ), e.$$typeof) {
52
+ case j:
53
+ return "Portal";
54
+ case y:
55
+ return e.displayName || "Context";
56
+ case C:
57
+ return (e._context.displayName || "Context") + ".Consumer";
58
+ case k:
59
+ var r = e.render;
60
+ return e = e.displayName, e || (e = r.displayName || r.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
61
+ case D:
62
+ return r = e.displayName || null, r !== null ? r : t(e.type) || "Memo";
63
+ case x:
64
+ r = e._payload, e = e._init;
65
+ try {
66
+ return t(e(r));
67
+ } catch {
68
+ }
69
+ }
70
+ return null;
71
+ }
72
+ function c(e) {
73
+ return "" + e;
74
+ }
75
+ function l(e) {
76
+ try {
77
+ c(e);
78
+ var r = !1;
79
+ } catch {
80
+ r = !0;
81
+ }
82
+ if (r) {
83
+ r = console;
84
+ var n = r.error, o = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
85
+ return n.call(
86
+ r,
87
+ "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
88
+ o
89
+ ), c(e);
90
+ }
91
+ }
92
+ function f(e) {
93
+ if (e === E) return "<>";
94
+ if (typeof e == "object" && e !== null && e.$$typeof === x)
95
+ return "<...>";
96
+ try {
97
+ var r = t(e);
98
+ return r ? "<" + r + ">" : "<...>";
99
+ } catch {
100
+ return "<...>";
101
+ }
102
+ }
103
+ function i() {
104
+ var e = A.A;
105
+ return e === null ? null : e.getOwner();
106
+ }
107
+ function s() {
108
+ return Error("react-stack-top-frame");
109
+ }
110
+ function u(e) {
111
+ if (v.call(e, "key")) {
112
+ var r = Object.getOwnPropertyDescriptor(e, "key").get;
113
+ if (r && r.isReactWarning) return !1;
114
+ }
115
+ return e.key !== void 0;
116
+ }
117
+ function d(e, r) {
118
+ function n() {
119
+ V || (V = !0, console.error(
120
+ "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
121
+ r
122
+ ));
123
+ }
124
+ n.isReactWarning = !0, Object.defineProperty(e, "key", {
125
+ get: n,
126
+ configurable: !0
127
+ });
128
+ }
129
+ function m() {
130
+ var e = t(this.type);
131
+ return q[e] || (q[e] = !0, console.error(
132
+ "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
133
+ )), e = this.props.ref, e !== void 0 ? e : null;
134
+ }
135
+ function _(e, r, n, o, $, M) {
136
+ var a = n.ref;
137
+ return e = {
138
+ $$typeof: h,
139
+ type: e,
140
+ key: r,
141
+ props: n,
142
+ _owner: o
143
+ }, (a !== void 0 ? a : null) !== null ? Object.defineProperty(e, "ref", {
144
+ enumerable: !1,
145
+ get: m
146
+ }) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
147
+ configurable: !1,
148
+ enumerable: !1,
149
+ writable: !0,
150
+ value: 0
151
+ }), Object.defineProperty(e, "_debugInfo", {
152
+ configurable: !1,
153
+ enumerable: !1,
154
+ writable: !0,
155
+ value: null
156
+ }), Object.defineProperty(e, "_debugStack", {
157
+ configurable: !1,
158
+ enumerable: !1,
159
+ writable: !0,
160
+ value: $
161
+ }), Object.defineProperty(e, "_debugTask", {
162
+ configurable: !1,
163
+ enumerable: !1,
164
+ writable: !0,
165
+ value: M
166
+ }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
167
+ }
168
+ function R(e, r, n, o, $, M) {
169
+ var a = r.children;
170
+ if (a !== void 0)
171
+ if (o)
172
+ if (te(a)) {
173
+ for (o = 0; o < a.length; o++)
174
+ T(a[o]);
175
+ Object.freeze && Object.freeze(a);
176
+ } else
177
+ console.error(
178
+ "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
179
+ );
180
+ else T(a);
181
+ if (v.call(r, "key")) {
182
+ a = t(e);
183
+ var b = Object.keys(r).filter(function(ne) {
184
+ return ne !== "key";
185
+ });
186
+ o = 0 < b.length ? "{key: someKey, " + b.join(": ..., ") + ": ...}" : "{key: someKey}", G[a + o] || (b = 0 < b.length ? "{" + b.join(": ..., ") + ": ...}" : "{}", console.error(
187
+ `A props object containing a "key" prop is being spread into JSX:
188
+ let props = %s;
189
+ <%s {...props} />
190
+ React keys must be passed directly to JSX without using spread:
191
+ let props = %s;
192
+ <%s key={someKey} {...props} />`,
193
+ o,
194
+ a,
195
+ b,
196
+ a
197
+ ), G[a + o] = !0);
198
+ }
199
+ if (a = null, n !== void 0 && (l(n), a = "" + n), u(r) && (l(r.key), a = "" + r.key), "key" in r) {
200
+ n = {};
201
+ for (var U in r)
202
+ U !== "key" && (n[U] = r[U]);
203
+ } else n = r;
204
+ return a && d(
205
+ n,
206
+ typeof e == "function" ? e.displayName || e.name || "Unknown" : e
207
+ ), _(
208
+ e,
209
+ a,
210
+ n,
211
+ i(),
212
+ $,
213
+ M
214
+ );
215
+ }
216
+ function T(e) {
217
+ g(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === x && (e._payload.status === "fulfilled" ? g(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
218
+ }
219
+ function g(e) {
220
+ return typeof e == "object" && e !== null && e.$$typeof === h;
221
+ }
222
+ var p = oe, h = /* @__PURE__ */ Symbol.for("react.transitional.element"), j = /* @__PURE__ */ Symbol.for("react.portal"), E = /* @__PURE__ */ Symbol.for("react.fragment"), F = /* @__PURE__ */ Symbol.for("react.strict_mode"), W = /* @__PURE__ */ Symbol.for("react.profiler"), C = /* @__PURE__ */ Symbol.for("react.consumer"), y = /* @__PURE__ */ Symbol.for("react.context"), k = /* @__PURE__ */ Symbol.for("react.forward_ref"), P = /* @__PURE__ */ Symbol.for("react.suspense"), N = /* @__PURE__ */ Symbol.for("react.suspense_list"), D = /* @__PURE__ */ Symbol.for("react.memo"), x = /* @__PURE__ */ Symbol.for("react.lazy"), w = /* @__PURE__ */ Symbol.for("react.activity"), L = /* @__PURE__ */ Symbol.for("react.client.reference"), A = p.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, v = Object.prototype.hasOwnProperty, te = Array.isArray, I = console.createTask ? console.createTask : function() {
223
+ return null;
224
+ };
225
+ p = {
226
+ react_stack_bottom_frame: function(e) {
227
+ return e();
228
+ }
229
+ };
230
+ var V, q = {}, z = p.react_stack_bottom_frame.bind(
231
+ p,
232
+ s
233
+ )(), J = I(f(s)), G = {};
234
+ S.Fragment = E, S.jsx = function(e, r, n) {
235
+ var o = 1e4 > A.recentlyCreatedOwnerStacks++;
236
+ return R(
237
+ e,
238
+ r,
239
+ n,
240
+ !1,
241
+ o ? Error("react-stack-top-frame") : z,
242
+ o ? I(f(e)) : J
243
+ );
244
+ }, S.jsxs = function(e, r, n) {
245
+ var o = 1e4 > A.recentlyCreatedOwnerStacks++;
246
+ return R(
247
+ e,
248
+ r,
249
+ n,
250
+ !0,
251
+ o ? Error("react-stack-top-frame") : z,
252
+ o ? I(f(e)) : J
253
+ );
254
+ };
255
+ })()), S;
256
+ }
257
+ var Z;
258
+ function ce() {
259
+ return Z || (Z = 1, process.env.NODE_ENV === "production" ? Y.exports = se() : Y.exports = ue()), Y.exports;
260
+ }
261
+ var le = ce();
262
+ const Q = /* @__PURE__ */ new Map();
263
+ function re() {
264
+ return typeof window < "u" && typeof document < "u";
265
+ }
266
+ function K(t) {
267
+ if (!re()) return Promise.resolve();
268
+ const c = Q.get(t);
269
+ if (c) return c;
270
+ const l = new Promise((f, i) => {
271
+ const s = document.querySelector(
272
+ `script[src="${t}"]`
273
+ );
274
+ if (s?.dataset.loaded === "true") {
275
+ f();
276
+ return;
277
+ }
278
+ const u = s ?? document.createElement("script");
279
+ u.src = t, u.async = !0;
280
+ const d = () => {
281
+ u.dataset.loaded = "true", _(), f();
282
+ }, m = () => {
283
+ _(), i(new Error(`Failed to load script: ${t}`));
284
+ }, _ = () => {
285
+ u.removeEventListener("load", d), u.removeEventListener("error", m);
286
+ };
287
+ u.addEventListener("load", d), u.addEventListener("error", m), s || document.head.appendChild(u);
288
+ });
289
+ return Q.set(t, l), l;
290
+ }
291
+ async function ee(t, { timeoutMs: c = 15e3, intervalMs: l = 50 } = {}) {
292
+ if (!re()) return;
293
+ const f = Date.now();
294
+ for (; ; ) {
295
+ if (t()) return;
296
+ if (Date.now() - f > c)
297
+ throw new Error("Timed out waiting for condition.");
298
+ await new Promise((i) => setTimeout(i, l));
299
+ }
300
+ }
301
+ function fe(t) {
302
+ return t.endsWith("/") ? t : `${t}/`;
303
+ }
304
+ function de() {
305
+ if (typeof location > "u") return null;
306
+ const c = new RegExp("[\\?&]lang=([^&#]*)").exec(location.search);
307
+ return c === null ? null : decodeURIComponent(c[1].replace(/\+/g, " "));
308
+ }
309
+ function _e({
310
+ libraryPath: t = "/charting_library/",
311
+ chartingLibraryScriptUrl: c,
312
+ udfBundleUrl: l = "/datafeeds/udf/dist/bundle.js",
313
+ datafeedUrl: f = "https://demo_feed.tradingview.com",
314
+ symbol: i = "AAPL",
315
+ interval: s = "D",
316
+ locale: u,
317
+ autosize: d = !0,
318
+ fullscreen: m = !1,
319
+ disabledFeatures: _ = ["use_localstorage_for_settings"],
320
+ enabledFeatures: R = ["study_templates"],
321
+ chartsStorageUrl: T = "https://saveload.tradingview.com",
322
+ chartsStorageApiVersion: g = "1.1",
323
+ clientId: p = "tradingview.com",
324
+ userId: h = "public_user_id",
325
+ studiesOverrides: j = {},
326
+ widgetOptions: E,
327
+ className: F,
328
+ style: W,
329
+ onReady: C
330
+ }) {
331
+ const y = X(null), k = X(null), P = ae(() => fe(t), [t]), N = c ?? `${P}charting_library.js`;
332
+ return ie(() => {
333
+ let D = !1;
334
+ async function x() {
335
+ if (!y.current || typeof window > "u" || (await K(N), await ee(() => !!window.TradingView?.widget), l && (await K(l), await ee(() => !!window.Datafeeds?.UDFCompatibleDatafeed)), D)) return;
336
+ const w = window.TradingView?.widget;
337
+ if (!w)
338
+ throw new Error(
339
+ "TradingView widget constructor not found. Make sure the Charting Library script is reachable."
340
+ );
341
+ const L = E?.datafeed ?? (window.Datafeeds?.UDFCompatibleDatafeed ? new window.Datafeeds.UDFCompatibleDatafeed(f) : void 0);
342
+ if (!L)
343
+ throw new Error(
344
+ "No datafeed available. Provide `udfBundleUrl` (to load UDF) or pass `widgetOptions.datafeed`."
345
+ );
346
+ const A = {
347
+ symbol: i,
348
+ interval: s,
349
+ container: y.current,
350
+ library_path: P,
351
+ locale: u ?? de() ?? "en",
352
+ datafeed: L,
353
+ disabled_features: _,
354
+ enabled_features: R,
355
+ charts_storage_url: T,
356
+ charts_storage_api_version: g,
357
+ client_id: p,
358
+ user_id: h,
359
+ fullscreen: m,
360
+ autosize: d,
361
+ studies_overrides: j,
362
+ ...E
363
+ }, v = new w(A);
364
+ k.current = v, v.onChartReady(() => {
365
+ C?.(v);
366
+ });
367
+ }
368
+ return x().catch((w) => {
369
+ console.error(w);
370
+ }), () => {
371
+ D = !0, k.current?.remove(), k.current = null;
372
+ };
373
+ }, [
374
+ N,
375
+ l,
376
+ f,
377
+ P,
378
+ i,
379
+ s,
380
+ u,
381
+ d,
382
+ m,
383
+ T,
384
+ g,
385
+ p,
386
+ h,
387
+ // arrays/objects:
388
+ _,
389
+ R,
390
+ j,
391
+ E,
392
+ C
393
+ ]), /* @__PURE__ */ le.jsx(
394
+ "div",
395
+ {
396
+ ref: y,
397
+ className: F,
398
+ style: {
399
+ width: "100%",
400
+ height: "100%",
401
+ ...W
402
+ }
403
+ }
404
+ );
405
+ }
406
+ export {
407
+ _e as TradingViewWidget
408
+ };
@@ -0,0 +1,13 @@
1
+ import type { TradingViewWidgetConstructor, TradingViewWidgetProps, UdfCompatibleDatafeedConstructor } from "./types";
2
+ declare global {
3
+ interface Window {
4
+ TradingView?: {
5
+ widget?: TradingViewWidgetConstructor;
6
+ };
7
+ Datafeeds?: {
8
+ UDFCompatibleDatafeed?: UdfCompatibleDatafeedConstructor;
9
+ };
10
+ }
11
+ }
12
+ export declare function TradingViewWidget({ libraryPath, chartingLibraryScriptUrl, udfBundleUrl, datafeedUrl, symbol, interval, locale, autosize, fullscreen, disabledFeatures, enabledFeatures, chartsStorageUrl, chartsStorageApiVersion, clientId, userId, studiesOverrides, widgetOptions, className, style, onReady, }: TradingViewWidgetProps): import("react/jsx-runtime").JSX.Element;
13
+ //# sourceMappingURL=TradingViewWidget.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TradingViewWidget.d.ts","sourceRoot":"","sources":["../../src/tradingview/TradingViewWidget.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,4BAA4B,EAE5B,sBAAsB,EAEtB,gCAAgC,EACjC,MAAM,SAAS,CAAC;AAEjB,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,WAAW,CAAC,EAAE;YAAE,MAAM,CAAC,EAAE,4BAA4B,CAAA;SAAE,CAAC;QACxD,SAAS,CAAC,EAAE;YAAE,qBAAqB,CAAC,EAAE,gCAAgC,CAAA;SAAE,CAAC;KAC1E;CACF;AAaD,wBAAgB,iBAAiB,CAAC,EAChC,WAAkC,EAClC,wBAAwB,EACxB,YAA8C,EAC9C,WAAiD,EACjD,MAAe,EACf,QAAc,EACd,MAAM,EACN,QAAe,EACf,UAAkB,EAClB,gBAAoD,EACpD,eAAqC,EACrC,gBAAqD,EACrD,uBAA+B,EAC/B,QAA4B,EAC5B,MAAyB,EACzB,gBAAqB,EACrB,aAAa,EACb,SAAS,EACT,KAAK,EACL,OAAO,GACR,EAAE,sBAAsB,2CAmHxB"}
@@ -0,0 +1,6 @@
1
+ export declare function loadScript(src: string): Promise<void>;
2
+ export declare function waitFor(predicate: () => boolean, { timeoutMs, intervalMs }?: {
3
+ timeoutMs?: number;
4
+ intervalMs?: number;
5
+ }): Promise<void>;
6
+ //# sourceMappingURL=loadScript.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loadScript.d.ts","sourceRoot":"","sources":["../../src/tradingview/loadScript.ts"],"names":[],"mappings":"AAMA,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA6CrD;AAED,wBAAsB,OAAO,CAC3B,SAAS,EAAE,MAAM,OAAO,EACxB,EAAE,SAAiB,EAAE,UAAe,EAAE,GAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAO,GACvF,OAAO,CAAC,IAAI,CAAC,CAYf"}
@@ -0,0 +1,61 @@
1
+ export type TradingViewResolution = string;
2
+ export type TradingViewWidgetOptions = {
3
+ symbol?: string;
4
+ interval?: TradingViewResolution;
5
+ container?: HTMLElement | string;
6
+ library_path?: string;
7
+ locale?: string;
8
+ datafeed?: unknown;
9
+ disabled_features?: string[];
10
+ enabled_features?: string[];
11
+ charts_storage_url?: string;
12
+ charts_storage_api_version?: string;
13
+ client_id?: string;
14
+ user_id?: string;
15
+ fullscreen?: boolean;
16
+ autosize?: boolean;
17
+ studies_overrides?: Record<string, unknown>;
18
+ theme?: "Light" | "Dark";
19
+ [key: string]: unknown;
20
+ };
21
+ export type TradingViewWidgetInstance = {
22
+ remove: () => void;
23
+ onChartReady: (cb: () => void) => void;
24
+ headerReady: () => Promise<void>;
25
+ createButton: () => HTMLElement;
26
+ showNoticeDialog: (args: {
27
+ title: string;
28
+ body: string;
29
+ callback?: () => void;
30
+ }) => void;
31
+ };
32
+ export type TradingViewWidgetConstructor = new (options: TradingViewWidgetOptions) => TradingViewWidgetInstance;
33
+ export type UdfCompatibleDatafeedConstructor = new (datafeedUrl: string) => unknown;
34
+ export type TradingViewWidgetProps = {
35
+ /** Path where partners host the TradingView `charting_library` folder (must end with `/`). */
36
+ libraryPath?: string;
37
+ /** URL to the TradingView Charting Library UMD bundle (defaults to `${libraryPath}charting_library.js`). */
38
+ chartingLibraryScriptUrl?: string;
39
+ /** URL to UDF bundle script that provides `window.Datafeeds.UDFCompatibleDatafeed`. */
40
+ udfBundleUrl?: string;
41
+ /** UDF base URL (example: `https://demo_feed.tradingview.com`). */
42
+ datafeedUrl?: string;
43
+ symbol?: string;
44
+ interval?: TradingViewResolution;
45
+ locale?: string;
46
+ autosize?: boolean;
47
+ fullscreen?: boolean;
48
+ disabledFeatures?: string[];
49
+ enabledFeatures?: string[];
50
+ chartsStorageUrl?: string;
51
+ chartsStorageApiVersion?: string;
52
+ clientId?: string;
53
+ userId?: string;
54
+ studiesOverrides?: Record<string, unknown>;
55
+ /** Extra raw widget options to merge in (advanced). */
56
+ widgetOptions?: TradingViewWidgetOptions;
57
+ className?: string;
58
+ style?: React.CSSProperties;
59
+ onReady?: (widget: TradingViewWidgetInstance) => void;
60
+ };
61
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/tradingview/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,qBAAqB,GAAG,MAAM,CAAC;AAI3C,MAAM,MAAM,wBAAwB,GAAG;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,qBAAqB,CAAC;IACjC,SAAS,CAAC,EAAE,WAAW,GAAG,MAAM,CAAC;IACjC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,0BAA0B,CAAC,EAAE,MAAM,CAAC;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC5C,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,YAAY,EAAE,CAAC,EAAE,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC;IACvC,WAAW,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,YAAY,EAAE,MAAM,WAAW,CAAC;IAChC,gBAAgB,EAAE,CAAC,IAAI,EAAE;QACvB,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;KACvB,KAAK,IAAI,CAAC;CACZ,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG,KACzC,OAAO,EAAE,wBAAwB,KAC9B,yBAAyB,CAAC;AAE/B,MAAM,MAAM,gCAAgC,GAAG,KAAK,WAAW,EAAE,MAAM,KAAK,OAAO,CAAC;AAEpF,MAAM,MAAM,sBAAsB,GAAG;IACnC,8FAA8F;IAC9F,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4GAA4G;IAC5G,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAElC,uFAAuF;IACvF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,mEAAmE;IACnE,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,qBAAqB,CAAC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAE3B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAE3C,uDAAuD;IACvD,aAAa,CAAC,EAAE,wBAAwB,CAAC;IAEzC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAE5B,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,yBAAyB,KAAK,IAAI,CAAC;CACvD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "widget-iccandle",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "type": "module",
5
5
  "author": "ICCandle",
6
6
  "license": "MIT",
@@ -19,7 +19,7 @@
19
19
  ],
20
20
  "scripts": {
21
21
  "dev": "vite",
22
- "build": "tsc -b && vite build",
22
+ "build": "vite build && tsc -p tsconfig.lib.json",
23
23
  "prepublishOnly": "npm run build",
24
24
  "lint": "eslint .",
25
25
  "preview": "vite preview"
@@ -27,14 +27,24 @@
27
27
  "files": [
28
28
  "dist"
29
29
  ],
30
- "dependencies": {
31
- "@tailwindcss/vite": "^4.1.18",
32
- "react": "^19.2.0",
33
- "react-dom": "^19.2.0",
34
- "tailwindcss": "^4.1.18"
30
+ "main": "./dist/index.cjs",
31
+ "module": "./dist/index.js",
32
+ "types": "./dist/index.d.ts",
33
+ "exports": {
34
+ ".": {
35
+ "types": "./dist/index.d.ts",
36
+ "import": "./dist/index.js",
37
+ "require": "./dist/index.cjs"
38
+ }
39
+ },
40
+ "dependencies": {},
41
+ "peerDependencies": {
42
+ "react": ">=18",
43
+ "react-dom": ">=18"
35
44
  },
36
45
  "devDependencies": {
37
46
  "@eslint/js": "^9.39.1",
47
+ "@tailwindcss/vite": "^4.1.18",
38
48
  "@types/node": "^24.10.1",
39
49
  "@types/react": "^19.2.7",
40
50
  "@types/react-dom": "^19.2.3",
@@ -43,6 +53,9 @@
43
53
  "eslint-plugin-react-hooks": "^7.0.1",
44
54
  "eslint-plugin-react-refresh": "^0.4.24",
45
55
  "globals": "^16.5.0",
56
+ "react": "^19.2.0",
57
+ "react-dom": "^19.2.0",
58
+ "tailwindcss": "^4.1.18",
46
59
  "typescript": "~5.9.3",
47
60
  "typescript-eslint": "^8.48.0",
48
61
  "vite": "^7.3.1"